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 BitWizrd.HuntRomero77Alamo
{
[BepInPlugin("BitWizrd.HuntRomero77Alamo", "HuntRomero77Alamo", "1.0.1")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class HuntRomero77AlamoPlugin : 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(), "BitWizrd.HuntRomero77Alamo");
OtherLoader.RegisterDirectLoad(BasePath, "BitWizrd.HuntRomero77Alamo", "", "romero77alamo", "", "");
}
}
}
namespace BitWizrd.Alamo
{
public class AlofsDevice : MonoBehaviour
{
private enum EState
{
Open,
Closed,
Feeding,
Closing
}
public BreakActionWeapon BreakActionWeapon;
public Transform FeedDevice;
public Transform ProxyRoundPos;
public Transform ProxyRoundPosOpen;
public Transform FeederLever;
public Transform FeederLeverIdlePos;
public Transform FeederLeverActivePos;
[Header("Proximity Detection")]
public Transform DetectionPoint;
public float Range = 0.02f;
public float OpenAngle;
public float ClosedAngle;
public float FeedingAngle;
public float Speed = 180f;
public float ForeClosingThreshhold;
public Transform FeedDeviceFollower;
public Transform FollowerEmptyPos;
public Transform FollowerFilledPos;
private float currentRotation;
private Quaternion _targetRotation;
private bool isOpen = false;
private bool _wasChamberFull = false;
private bool _wasFullAndSpent = false;
private FVRFirearmMovingProxyRound m_proxy;
private float _origSpeed;
private bool lastFrameLatched = false;
private bool _isLeverActive = false;
private float _leverRotationProgress = 0f;
private const float LEVER_CYCLE_TIME = 0.25f;
private bool _hasTriggeredLeverCycle = false;
private float curRot;
private float tarRot;
private bool _wasInRange = false;
private bool _prevChamberFull = false;
private bool _prevChamberSpent = false;
private bool _hasDetectedEjection = false;
private bool _wasHingeOpenEnough = false;
private EState _state;
private void Start()
{
//IL_0035: 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_0055: 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_007f: Expected O, but got Unknown
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_011c: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)FeedDevice == (Object)null)
{
((Behaviour)this).enabled = false;
return;
}
FeedDevice.localRotation = Quaternion.Euler(0f, 0f, ClosedAngle);
_targetRotation = Quaternion.Euler(0f, 0f, ClosedAngle);
currentRotation = ClosedAngle;
_state = EState.Closed;
isOpen = false;
GameObject val = new GameObject("m_proxyRound");
m_proxy = val.AddComponent<FVRFirearmMovingProxyRound>();
m_proxy.Init(((Component)this).transform);
val.transform.localPosition = ProxyRoundPos.localPosition;
_origSpeed = Speed;
((FVRFireArm)BreakActionWeapon).Magazine.IsDropInLoadable = false;
_wasChamberFull = BreakActionWeapon.Barrels[0].Chamber.IsFull;
if ((Object)(object)FeederLever != (Object)null)
{
_isLeverActive = false;
_leverRotationProgress = 0f;
FeederLever.localRotation = FeederLeverIdlePos.localRotation;
}
}
private void FixedUpdate()
{
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
bool isFull = BreakActionWeapon.Barrels[0].Chamber.IsFull;
bool isSpent = BreakActionWeapon.Barrels[0].Chamber.IsSpent;
float num = Mathf.Abs(((Component)BreakActionWeapon.Hinge).transform.localEulerAngles.x);
if (num >= BreakActionWeapon.HingeEjectLimit)
{
_wasHingeOpenEnough = true;
}
else
{
_wasHingeOpenEnough = false;
_hasDetectedEjection = false;
}
bool flag = _wasHingeOpenEnough && _prevChamberFull && _prevChamberSpent && !isFull;
_prevChamberFull = isFull;
_prevChamberSpent = isSpent;
if (isFull)
{
_hasDetectedEjection = false;
}
if (flag && !_hasDetectedEjection && _state == EState.Closed)
{
_hasDetectedEjection = true;
StartFeeding();
}
}
private void Update()
{
//IL_0192: Unknown result type (might be due to invalid IL or missing references)
//IL_0242: Unknown result type (might be due to invalid IL or missing references)
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
bool flag = BreakActionWeapon.IsLatched && !lastFrameLatched;
lastFrameLatched = BreakActionWeapon.IsLatched;
bool flag2 = false;
float num = 1f;
if ((Object)(object)GM.CurrentMovementManager != (Object)null && (Object)(object)DetectionPoint != (Object)null)
{
for (int i = 0; i < GM.CurrentMovementManager.Hands.Length; i++)
{
FVRViveHand val = GM.CurrentMovementManager.Hands[i];
if ((Object)(object)val != (Object)null && (Object)(object)val.CurrentInteractable != (Object)null && val.CurrentInteractable is FVRFireArmRound)
{
float num2 = Vector3.Distance(((Component)val.CurrentInteractable).transform.position, DetectionPoint.position);
if (num2 < num)
{
num = num2;
flag2 = true;
}
}
}
}
if (flag2)
{
if (num <= Range)
{
tarRot = (Range - num) / Range;
}
else
{
tarRot = 0f;
}
}
else
{
tarRot = 0f;
}
if (_state != EState.Feeding && tarRot != curRot)
{
curRot = tarRot;
FeedDevice.localEulerAngles = new Vector3(0f, 0f, Mathf.Lerp(ClosedAngle, OpenAngle, curRot * 2f));
if (curRot > 0.25f)
{
if (_state == EState.Closed)
{
_state = EState.Open;
isOpen = true;
((FVRFireArm)BreakActionWeapon).PlayAudioEvent((FirearmAudioEventType)21, 1f);
}
}
else if (_state == EState.Open)
{
_state = EState.Closing;
isOpen = false;
((FVRFireArm)BreakActionWeapon).PlayAudioEvent((FirearmAudioEventType)20, 1f);
}
}
if (flag && _state == EState.Feeding)
{
_state = EState.Closing;
FeedDevice.localEulerAngles = new Vector3(0f, 0f, ClosedAngle);
isOpen = false;
Speed = _origSpeed;
((FVRFireArm)BreakActionWeapon).PlayAudioEvent((FirearmAudioEventType)20, 1f);
_hasTriggeredLeverCycle = false;
if (m_proxy.IsFull && !BreakActionWeapon.Barrels[0].Chamber.IsFull)
{
ChamberRound();
}
}
if (_state == EState.Closed && !m_proxy.IsFull && ((FVRFireArm)BreakActionWeapon).Magazine.HasARound())
{
FillTube();
_hasTriggeredLeverCycle = false;
}
if (_state == EState.Open)
{
((FVRFireArm)BreakActionWeapon).Magazine.IsDropInLoadable = true;
}
else
{
((FVRFireArm)BreakActionWeapon).Magazine.IsDropInLoadable = false;
}
UpdateRotation();
UpdateProxyRoundPosition();
}
private void UpdateRotation()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_0242: Unknown result type (might be due to invalid IL or missing references)
//IL_0252: 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_0123: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01db: Unknown result type (might be due to invalid IL or missing references)
//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
//IL_018d: 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_019f: Unknown result type (might be due to invalid IL or missing references)
float x = ((Component)BreakActionWeapon.Hinge).transform.localEulerAngles.x;
bool flag = x < ForeClosingThreshhold && x >= 0f && BreakActionWeapon.IsLatched;
bool flag2 = x >= BreakActionWeapon.HingeEjectLimit && x < 180f;
if (flag)
{
_hasTriggeredLeverCycle = false;
if (_state == EState.Feeding)
{
_state = EState.Closing;
FeedDevice.localEulerAngles = new Vector3(0f, 0f, ClosedAngle);
isOpen = false;
((FVRFireArm)BreakActionWeapon).PlayAudioEvent((FirearmAudioEventType)20, 1f);
if ((Object)(object)FeederLever != (Object)null)
{
_isLeverActive = false;
_leverRotationProgress = 0f;
FeederLever.localRotation = FeederLeverIdlePos.localRotation;
}
}
}
if (_state == EState.Feeding && flag2)
{
FeedDevice.localEulerAngles = new Vector3(0f, 0f, FeedingAngle);
if ((Object)(object)FeederLever != (Object)null && _isLeverActive)
{
_leverRotationProgress += Time.deltaTime / 0.25f;
if (_leverRotationProgress <= 0.5f)
{
float num = _leverRotationProgress * 2f;
FeederLever.localRotation = Quaternion.Slerp(FeederLeverIdlePos.localRotation, FeederLeverActivePos.localRotation, num);
}
else
{
float num2 = (_leverRotationProgress - 0.5f) * 2f;
FeederLever.localRotation = Quaternion.Slerp(FeederLeverActivePos.localRotation, FeederLeverIdlePos.localRotation, num2);
}
if (_leverRotationProgress >= 1f)
{
_isLeverActive = false;
_leverRotationProgress = 0f;
ChamberRound();
}
}
}
else if (_state == EState.Closing)
{
FeedDevice.localEulerAngles = new Vector3(0f, 0f, ClosedAngle);
if (Mathf.Approximately(FeedDevice.localEulerAngles.z, ClosedAngle))
{
_state = EState.Closed;
isOpen = false;
Speed = _origSpeed;
}
}
}
public bool StartFeeding()
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
if (!_hasDetectedEjection || !_wasHingeOpenEnough)
{
return false;
}
_state = EState.Feeding;
FeedDevice.localEulerAngles = new Vector3(0f, 0f, FeedingAngle);
Speed = _origSpeed;
if (!m_proxy.IsFull && ((FVRFireArm)BreakActionWeapon).Magazine.HasARound())
{
FillTube();
}
if ((Object)(object)FeederLever != (Object)null)
{
_isLeverActive = true;
_leverRotationProgress = 0f;
}
return true;
}
private void FillTube()
{
((FVRFireArm)BreakActionWeapon).PlayAudioEvent((FirearmAudioEventType)42, 1f);
m_proxy.SetFromPrefabReference(((FVRFireArm)BreakActionWeapon).Magazine.RemoveRound(true));
}
private bool ChamberRound()
{
if (!m_proxy.IsFull || BreakActionWeapon.Barrels[0].Chamber.IsFull)
{
return false;
}
((FVRFireArm)BreakActionWeapon).PlayAudioEvent((FirearmAudioEventType)42, 1f);
BreakActionWeapon.Barrels[0].Chamber.SetRound(m_proxy.Round, false);
m_proxy.ClearProxy();
if (((FVRFireArm)BreakActionWeapon).Magazine.HasARound())
{
FillTube();
}
return true;
}
private void UpdateProxyRoundPosition()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: 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_0043: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
//IL_0108: Unknown result type (might be due to invalid IL or missing references)
//IL_015b: Unknown result type (might be due to invalid IL or missing references)
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_0182: Unknown result type (might be due to invalid IL or missing references)
if (_state != 0 && m_proxy.ProxyRound.position != ProxyRoundPos.position)
{
m_proxy.ProxyRound.position = ProxyRoundPos.position;
m_proxy.ProxyRound.localScale = ProxyRoundPos.localScale;
}
else if (_state == EState.Open && m_proxy.ProxyRound.position != ProxyRoundPosOpen.position)
{
m_proxy.ProxyRound.position = ProxyRoundPosOpen.position;
m_proxy.ProxyRound.localScale = ProxyRoundPosOpen.localScale;
}
if (m_proxy.IsFull && (Object)(object)FeedDeviceFollower != (Object)null && FeedDeviceFollower.position != FollowerFilledPos.position)
{
FeedDeviceFollower.position = FollowerFilledPos.position;
}
else if (!m_proxy.IsFull && (Object)(object)FeedDeviceFollower != (Object)null && FeedDeviceFollower.position != FollowerEmptyPos.position)
{
FeedDeviceFollower.position = FollowerEmptyPos.position;
}
}
}
}