using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using H3VRUtils;
using HarmonyLib;
using OtherLoader;
using UnityEngine;
using UnityEngine.UI;
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
public class RPMCalculator : MonoBehaviour
{
[Header("Assign only one bugee here")]
public ClosedBolt ClosedBolt;
public OpenBoltReceiverBolt OpenBolt;
public HandgunSlide HandgunSlide;
[Header("Simulation Settings (Don't touch this bugee unless you know how physics in Unity works)")]
public float SimStepSize = 0.0005f;
public int MaxSimSteps = 100000;
[Header("Forward Calculator - Results")]
public float Result_RPM;
public float Result_CycleTimeMS;
public float Result_RearwardTimeMS;
public float Result_ForwardTimeMS;
[Header("Reverse Calculator - Inputs")]
[Tooltip("The RPM you want the weapon to fire at.")]
public float Reverse_DesiredRPM = 600f;
[Tooltip("What percentage of the cycle the bolt spends travelling rearward. Remainder is the forward (spring) stroke. Typical range: 20 to 50.")]
[Range(1f, 99f)]
public float Reverse_RearwardSplitPercent = 35f;
[Tooltip("The maximum forward speed the spring drives the bolt toward. Pin this to a value that feels right for the weapon, the script will solve SpringStiffness to match.")]
public float Reverse_DesiredSpeedForward = 10f;
[Header("Reverse Calculator - Results")]
public float Reverse_Result_SpeedForward;
public float Reverse_Result_SpeedRearward;
public float Reverse_Result_SpringStiffness;
private float m_zForward;
private float m_zRear;
private float m_speedRearward;
private float m_speedForward;
private float m_springStiffness;
[ContextMenu("Calculate RPM")]
public void Calculate()
{
if (TryReadFields() && ValidateFields() && SimulateRearward(m_speedRearward, out var rearwardTime) && SimulateForward(m_speedForward, m_springStiffness, out var forwardTime))
{
float num = rearwardTime + forwardTime;
Result_RearwardTimeMS = rearwardTime * 1000f;
Result_ForwardTimeMS = forwardTime * 1000f;
Result_CycleTimeMS = num * 1000f;
Result_RPM = 60f / num;
Debug.Log((object)("[RPMCalculator] RPM: " + Result_RPM.ToString("F0") + " | Cycle: " + Result_CycleTimeMS.ToString("F2") + "ms | Rearward: " + Result_RearwardTimeMS.ToString("F2") + "ms | Forward: " + Result_ForwardTimeMS.ToString("F2") + "ms"));
}
}
[ContextMenu("Reverse Calculate this evil bugee ")]
public void ReverseCalculate()
{
if (!TryReadFields())
{
return;
}
if (Reverse_DesiredRPM <= 0f)
{
Debug.LogError((object)"[RPMCalculator] Reverse_DesiredRPM must be greater than 0.");
return;
}
if (Reverse_DesiredSpeedForward <= 0f)
{
Debug.LogError((object)"[RPMCalculator] Reverse_DesiredSpeedForward must be greater than 0.");
return;
}
if (Mathf.Approximately(m_zForward, m_zRear))
{
Debug.LogError((object)"[RPMCalculator] Forward and Rear positions are the same. No travel distance to simulate.");
return;
}
float num = 60f / Reverse_DesiredRPM;
float num2 = num * (Reverse_RearwardSplitPercent / 100f);
float targetForwardTime = num * (1f - Reverse_RearwardSplitPercent / 100f);
float num3 = Mathf.Abs(m_zForward - m_zRear);
float reverse_Result_SpeedRearward = 0f - num3 / num2;
if (!SolveSpringStiffness(targetForwardTime, Reverse_DesiredSpeedForward, out var result))
{
Debug.LogError((object)"[RPMCalculator] Could not solve SpringStiffness. Try increasing Reverse_DesiredSpeedForward or lowering Reverse_DesiredRPM \ufffd the bolt may not be physically able to cross the travel distance in the time available.");
return;
}
Reverse_Result_SpeedRearward = reverse_Result_SpeedRearward;
Reverse_Result_SpeedForward = Reverse_DesiredSpeedForward;
Reverse_Result_SpringStiffness = result;
Debug.Log((object)("[RPMCalculator] Reverse Result for " + Reverse_DesiredRPM.ToString("F0") + " RPM: | Speed_Rearward: " + reverse_Result_SpeedRearward.ToString("F4") + " | Speed_Forward: " + Reverse_DesiredSpeedForward.ToString("F4") + " | SpringStiffness: " + result.ToString("F4")));
}
private bool SolveSpringStiffness(float targetForwardTime, float speedForward, out float result)
{
result = 0f;
float num = Mathf.Abs(m_zForward - m_zRear) / speedForward;
if (targetForwardTime < num)
{
return false;
}
float num2 = 0.001f;
float num3 = 10000f;
for (int i = 0; i < 64; i++)
{
float num4 = (num2 + num3) * 0.5f;
SimulateForward(speedForward, num4, out var forwardTime);
if (forwardTime > targetForwardTime)
{
num2 = num4;
}
else
{
num3 = num4;
}
}
result = (num2 + num3) * 0.5f;
return true;
}
private bool SimulateRearward(float speedRearward, out float rearwardTime)
{
rearwardTime = 0f;
float num = m_zForward;
int num2 = 0;
while (num > m_zRear && num2 < MaxSimSteps)
{
num += speedRearward * SimStepSize;
num = Mathf.Max(num, m_zRear);
rearwardTime += SimStepSize;
num2++;
}
if (num2 >= MaxSimSteps)
{
Debug.LogError((object)"[RPMCalculator] Hit max steps on rearward stroke.");
return false;
}
return true;
}
private bool SimulateForward(float speedForward, float springStiffness, out float forwardTime)
{
forwardTime = 0f;
float num = m_zRear;
float num2 = 0f;
int num3 = 0;
while (num < m_zForward && num3 < MaxSimSteps)
{
num2 = Mathf.MoveTowards(num2, speedForward, SimStepSize * springStiffness);
num += num2 * SimStepSize;
num = Mathf.Min(num, m_zForward);
forwardTime += SimStepSize;
num3++;
}
if (num3 >= MaxSimSteps)
{
forwardTime = float.MaxValue;
return false;
}
return true;
}
private bool TryReadFields()
{
//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_024a: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Unknown result type (might be due to invalid IL or missing references)
//IL_0269: Unknown result type (might be due to invalid IL or missing references)
//IL_026e: Unknown result type (might be due to invalid IL or missing references)
//IL_0194: Unknown result type (might be due to invalid IL or missing references)
//IL_0199: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
int num = 0;
if ((Object)(object)ClosedBolt != (Object)null)
{
num++;
}
if ((Object)(object)OpenBolt != (Object)null)
{
num++;
}
if ((Object)(object)HandgunSlide != (Object)null)
{
num++;
}
if (num == 0)
{
Debug.LogError((object)"[RPMCalculator] No component assigned.");
return false;
}
if (num > 1)
{
Debug.LogError((object)"[RPMCalculator] More than one component assigned. Only assign one at a time.");
return false;
}
if ((Object)(object)ClosedBolt != (Object)null)
{
if ((Object)(object)ClosedBolt.Point_Bolt_Forward == (Object)null || (Object)(object)ClosedBolt.Point_Bolt_Rear == (Object)null)
{
Debug.LogError((object)"[RPMCalculator] ClosedBolt is missing Point_Bolt_Forward or Point_Bolt_Rear.");
return false;
}
m_zForward = ClosedBolt.Point_Bolt_Forward.localPosition.z;
m_zRear = ClosedBolt.Point_Bolt_Rear.localPosition.z;
m_speedRearward = ClosedBolt.Speed_Rearward;
m_speedForward = ClosedBolt.Speed_Forward;
m_springStiffness = ClosedBolt.SpringStiffness;
}
else if ((Object)(object)OpenBolt != (Object)null)
{
if ((Object)(object)OpenBolt.Point_Bolt_Forward == (Object)null || (Object)(object)OpenBolt.Point_Bolt_Rear == (Object)null)
{
Debug.LogError((object)"[RPMCalculator] OpenBoltReceiverBolt is missing Point_Bolt_Forward or Point_Bolt_Rear.");
return false;
}
m_zForward = OpenBolt.Point_Bolt_Forward.localPosition.z;
m_zRear = OpenBolt.Point_Bolt_Rear.localPosition.z;
m_speedRearward = OpenBolt.BoltSpeed_Rearward;
m_speedForward = OpenBolt.BoltSpeed_Forward;
m_springStiffness = OpenBolt.BoltSpringStiffness;
}
else
{
if ((Object)(object)HandgunSlide.Point_Slide_Forward == (Object)null || (Object)(object)HandgunSlide.Point_Slide_Rear == (Object)null)
{
Debug.LogError((object)"[RPMCalculator] HandgunSlide is missing Point_Slide_Forward or Point_Slide_Rear.");
return false;
}
m_zForward = HandgunSlide.Point_Slide_Forward.localPosition.z;
m_zRear = HandgunSlide.Point_Slide_Rear.localPosition.z;
m_speedRearward = HandgunSlide.Speed_Rearward;
m_speedForward = HandgunSlide.Speed_Forward;
m_springStiffness = HandgunSlide.SpringStiffness;
}
return true;
}
private bool ValidateFields()
{
if (Mathf.Approximately(m_zForward, m_zRear))
{
Debug.LogError((object)"[RPMCalculator] Forward and Rear positions are the same.");
return false;
}
if (m_speedRearward >= 0f)
{
Debug.LogError((object)("[RPMCalculator] Rearward speed should be negative. Current value: " + m_speedRearward));
return false;
}
if (m_speedForward <= 0f)
{
Debug.LogError((object)("[RPMCalculator] Forward speed must be greater than 0. Current value: " + m_speedForward));
return false;
}
if (m_springStiffness <= 0f)
{
Debug.LogError((object)("[RPMCalculator] SpringStiffness must be greater than 0. Current value: " + m_springStiffness));
return false;
}
return true;
}
}
public class ThreatSight : MonoBehaviour
{
[Header("Input Config")]
[Tooltip("PUT YOUR GUN IN HERE IT NEEDS TO KNOW")]
public FVRInteractiveObject myGun;
[Tooltip("FIREARM'S MUZZLE POINT FOR SNIFFING DIRECTION")]
public Transform muzzlePoint;
[Tooltip("MESHES WHICH MATERIAL YOU WISH TO CHANGE (BE FUCKING NORMAL AND FILL ALL IN)")]
public MeshRenderer[] meshTouch;
[Tooltip("DISTANCE IN METERS TO CHECK FOR MEAT")]
public float maxDistance;
[Tooltip("LAYERS THAT CAST WILL COLLIDE WITH AND SMELL")]
[Header("Mask Config")]
public LayerMask mask;
[Tooltip("COLOUR IF SOSIG NOT FOUND")]
[Header("Colour Inputs")]
public Color neutral;
[Tooltip("COLOUR IF SOSIG EVIL")]
public Color threat;
[Tooltip("COLOUR IF SOSIG IS GREEN FOR AN AMAZING REASON (friendly)")]
public Color friendly;
public void FixedUpdate()
{
if (myGun.m_isHeld)
{
LookForSosig();
}
}
public void LookForSosig()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0122: Unknown result type (might be due to invalid IL or missing references)
RaycastHit val = default(RaycastHit);
if (Physics.Raycast(muzzlePoint.position, muzzlePoint.forward, ref val, maxDistance, LayerMask.op_Implicit(mask)))
{
Sosig val2 = ((Component)((RaycastHit)(ref val)).collider).gameObject.GetComponentInParent<Sosig>();
if ((Object)(object)val2 == (Object)null)
{
SosigLink componentInParent = ((Component)((RaycastHit)(ref val)).collider).gameObject.GetComponentInParent<SosigLink>();
if ((Object)(object)componentInParent != (Object)null)
{
val2 = componentInParent.S;
}
}
if ((Object)(object)val2 != (Object)null && val2.GetIFF() != GM.CurrentPlayerBody.GetPlayerIFF())
{
MeshRenderer[] array = meshTouch;
foreach (MeshRenderer val3 in array)
{
((Renderer)val3).material.color = threat;
}
}
else if ((Object)(object)val2 != (Object)null && val2.GetIFF() == GM.CurrentPlayerBody.GetPlayerIFF())
{
MeshRenderer[] array2 = meshTouch;
foreach (MeshRenderer val4 in array2)
{
((Renderer)val4).material.color = friendly;
}
}
else if ((Object)(object)val2 == (Object)null)
{
MeshRenderer[] array3 = meshTouch;
foreach (MeshRenderer val5 in array3)
{
((Renderer)val5).material.color = neutral;
}
}
}
else
{
MeshRenderer[] array4 = meshTouch;
foreach (MeshRenderer val6 in array4)
{
((Renderer)val6).material.color = neutral;
}
}
}
}
public class SecondaryMagPos : MonoBehaviour
{
[Header("References")]
public FVRFireArm FireArm;
public FVRFireArmReloadTriggerWell TriggerWell;
[Header("Mount Override")]
public Transform MountPos;
public Transform EjectPos;
private Transform m_defaultMountPos;
private Transform m_defaultEjectPos;
private Vector3 m_defaultMountLocalPos;
private Quaternion m_defaultMountLocalRot;
private Vector3 m_defaultEjectLocalPos;
private Quaternion m_defaultEjectLocalRot;
private bool m_initialized = false;
private bool m_overrideActive = false;
private FVRFireArmMagazine m_pendingMag;
private int m_pendingStableFrames;
private const int kStableFramesRequired = 2;
private FVRFireArmMagazine m_appliedMag;
private void Start()
{
//IL_0095: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00df: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)FireArm == (Object)null || (Object)(object)TriggerWell == (Object)null)
{
((Behaviour)this).enabled = false;
return;
}
if ((Object)(object)MountPos == (Object)null)
{
((Behaviour)this).enabled = false;
return;
}
m_defaultMountPos = FireArm.MagazineMountPos;
m_defaultEjectPos = FireArm.MagazineEjectPos;
if ((Object)(object)m_defaultMountPos == (Object)null)
{
((Behaviour)this).enabled = false;
return;
}
m_defaultMountLocalPos = m_defaultMountPos.localPosition;
m_defaultMountLocalRot = m_defaultMountPos.localRotation;
if ((Object)(object)m_defaultEjectPos != (Object)null)
{
m_defaultEjectLocalPos = m_defaultEjectPos.localPosition;
m_defaultEjectLocalRot = m_defaultEjectPos.localRotation;
}
m_initialized = true;
m_pendingMag = null;
m_pendingStableFrames = 0;
m_appliedMag = null;
}
private void Update()
{
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
if (!m_initialized)
{
return;
}
FVRFireArmMagazine magazine = FireArm.Magazine;
if ((Object)(object)magazine == (Object)(object)m_pendingMag)
{
if (m_pendingStableFrames < 2)
{
m_pendingStableFrames++;
}
}
else
{
m_pendingMag = magazine;
m_pendingStableFrames = 0;
}
if (m_pendingStableFrames < 2 || (Object)(object)m_pendingMag == (Object)(object)m_appliedMag)
{
return;
}
FireArmMagazineType val = ((!TriggerWell.UsesTypeOverride) ? FireArm.MagazineType : TriggerWell.TypeOverride);
if ((Object)(object)m_pendingMag != (Object)null && m_pendingMag.MagazineType == val)
{
m_overrideActive = true;
m_appliedMag = m_pendingMag;
return;
}
if (m_overrideActive)
{
m_overrideActive = false;
RestoreDefaults();
}
m_appliedMag = null;
}
private void LateUpdate()
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
if (m_initialized && m_overrideActive)
{
m_defaultMountPos.position = MountPos.position;
m_defaultMountPos.rotation = MountPos.rotation;
if ((Object)(object)m_defaultEjectPos != (Object)null && (Object)(object)EjectPos != (Object)null)
{
m_defaultEjectPos.position = EjectPos.position;
m_defaultEjectPos.rotation = EjectPos.rotation;
}
}
}
private void RestoreDefaults()
{
//IL_0008: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: Unknown result type (might be due to invalid IL or missing references)
m_defaultMountPos.localPosition = m_defaultMountLocalPos;
m_defaultMountPos.localRotation = m_defaultMountLocalRot;
if ((Object)(object)m_defaultEjectPos != (Object)null)
{
m_defaultEjectPos.localPosition = m_defaultEjectLocalPos;
m_defaultEjectPos.localRotation = m_defaultEjectLocalRot;
}
}
private void OnDisable()
{
if (m_initialized)
{
RestoreDefaults();
}
}
private void OnDestroy()
{
if (m_initialized)
{
RestoreDefaults();
}
}
}
namespace Iqsbasiczz.Robinson_XCR_L;
[BepInPlugin("Iqsbasiczz.Robinson_XCR_L", "Robinson_XCR_L", "1.0.0")]
[BepInProcess("h3vr.exe")]
[Description("Built with MeatKit")]
[BepInDependency("h3vr.otherloader", "1.3.0")]
public class Robinson_XCR_LPlugin : 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(), "Iqsbasiczz.Robinson_XCR_L");
OtherLoader.RegisterDirectLoad(BasePath, "Iqsbasiczz.Robinson_XCR_L", "", "", "xcrlad", "");
}
}
public class ExpandedAmmoDisplay : MonoBehaviour
{
[Header("Ammo Counter Settings")]
[Tooltip("Text to display ammo left in the gun.")]
public Text UItext;
[Tooltip("Text to display maximum ammo.")]
public Text MaxAmmoText;
[Tooltip("Text to display the type of ammo.")]
public Text ammoTypeText;
[Tooltip("Adds a minimum character count. See tooltip for MinCharLength for more.")]
public bool AddMinCharLength;
[Tooltip("i.e if MinCharLength is 2 and the amount of rounds left is 5, it will display 05 instead of 5.")]
public int MinCharLength;
[Tooltip("Will not instantly be the correct amount of rounds, but will tick up/down until it is.")]
public bool enableDispLerp;
[Tooltip("MaxAmmo will also lerp according to the DispLerpAmt")]
public bool enableLerpForMaxAmmo;
[Tooltip("EnabledObjects will also lerp according to the DispLerpAmt")]
public bool enableLerpForEnabledObjects;
[Tooltip("From 0-1. The % amount moved towards its correct amount every 50th of a second.")]
[Range(0f, 0.2f)]
public float DispLerpAmt;
[Header("Alternate Displays")]
[Tooltip("Enables enabling/disabling objects based on rounds left in mag.")]
public bool EnabledObjects;
[Tooltip("Object enabled when there is no magazine.")]
public GameObject ObjectWhenEmpty;
[Tooltip("Element no. corresponds to rounds left. 0 means no rounds, 1 means one round. Enables the 5th object if there are 5 rounds, and so on.")]
public List<GameObject> Objects;
[Tooltip("Enables all objects under the round count. Enables the 0th, 1st, 2nd, 3rd objects if there are 3 rounds left, and so on.")]
public bool EnableAllUnderAmount;
[Tooltip("Overrides Objects. #0 means Objects' #0 displays from 0% to #0%, #1 means Objects' #1 displays from #0% to #1%, etc- written normally, not mathmatically (e.g 57.32)")]
public bool EnableBasedOnPercentage;
public List<float> ObjectPercentages;
[Header("Fire Mode Display")]
[Tooltip("Text to display the fire mode (e.g., Safe, Single, FullAuto, Burst).")]
public Text fireModeText;
[Tooltip("Image to display fire mode visually.")]
public Image fireModeImage;
[Tooltip("Sprites for each fire mode: 0=Safe, 1=Single, 2=FullAuto, 3=Burst, 4=Other.")]
public Sprite[] fireModeSprites;
[Header("Low Ammo Warning")]
[Tooltip("Enable sound and blink effects when ammo drops to a percentage of max.")]
public bool enableLowAmmoWarning;
[Tooltip("Percentage of max ammo at which the warning triggers (e.g. 25 means 25%).")]
[Range(0f, 100f)]
public float lowAmmoThresholdPercent = 25f;
[Tooltip("AudioSource used to play warning sounds.")]
public AudioSource warningAudioSource;
[Tooltip("Sound played once when ammo drops to or below the low ammo threshold.")]
public AudioClip lowAmmoClip;
[Tooltip("Sound played once when ammo is fully depleted (0 rounds).")]
public AudioClip depletedAmmoClip;
[Tooltip("Enable blinking on the ammo text when at or below the low ammo threshold.")]
public bool enableLowAmmoBlink;
[Tooltip("How many times per second the text blinks on/off.")]
public float blinkRate = 4f;
[Header("Chamber Indicator (optional)")]
[Tooltip("Enable a visual/text indicator when there is a round in the chamber.")]
public bool showChamberIndicator = false;
[Tooltip("If true the indicator will use an Image; otherwise it will use Text.")]
public bool chamberIndicatorUseImage = true;
[Tooltip("Image used to indicate a round is chambered. Assign only if using image mode.")]
public Image chamberIndicatorImage;
[Tooltip("Text used to indicate a round is chambered. Assign only if using text mode.")]
public Text chamberIndicatorText;
[Tooltip("Text shown when a round is chambered (used when chamberIndicatorUseImage == false).")]
public string chamberIndicatorString = "CH";
private FVRFireArm _fa;
private FVRFireArmMagazine _mag;
private FVRFirearmMovingProxyRound[] proxies;
private FVRFireArmChamber[] chambers;
private int lastAmountOfBullets;
private int lastAmountOfMaxBullets;
private int lastAmountOfBulletsForEnableObjects;
private bool _hasPlayedLowAmmoSound;
private bool _hasPlayedDepletedSound;
private bool _isBlinking;
private float _blinkTimer;
private int _previousAmmoCount = -1;
private bool _hadMagLastFrame;
private bool _isChamberIndicatorImageNotNull;
private bool _isChamberIndicatorTextNotNull;
private bool _isUItextNotNull;
private bool _isMaxAmmoTextNotNull;
private bool _isammoTypeTextNotNull;
private bool _isfireModeTextNotNull;
private bool _isfireModeImageNotNull;
private void Start()
{
NullCheck();
}
private void GetFirearmAndMag()
{
_fa = ((Component)this).GetComponent<FVRFireArm>() ?? ((Component)this).GetComponentInParent<FVRFireArm>();
if ((Object)(object)_fa != (Object)null)
{
_mag = _fa.Magazine;
if (chambers == null)
{
chambers = GetFireArmDeets.GetFireArmChamber(_fa);
}
proxies = GetFireArmDeets.GetFireArmProxySwitch(_fa, false);
}
else
{
_mag = null;
chambers = null;
proxies = null;
}
}
private void Update()
{
GetFirearmAndMag();
int ammoCount = GetAmmoCount();
int maxAmmoCount = GetMaxAmmoCount();
bool flag = (Object)(object)_mag != (Object)null;
if (_isUItextNotNull)
{
string text = CalculateAmmoCounterAmount(ammoCount, ref lastAmountOfBullets, enableDispLerp, DispLerpAmt, AddMinCharLength, MinCharLength);
UItext.text = text;
}
if (_isMaxAmmoTextNotNull)
{
string text2 = CalculateAmmoCounterAmount(maxAmmoCount, ref lastAmountOfMaxBullets, enableLerpForMaxAmmo, DispLerpAmt, AddMinCharLength, MinCharLength);
MaxAmmoText.text = text2;
}
if (_isammoTypeTextNotNull)
{
ammoTypeText.text = GetAmmoType();
}
if (_isfireModeTextNotNull || _isfireModeImageNotNull)
{
string fireMode = GetFireMode();
if (_isfireModeTextNotNull)
{
fireModeText.text = fireMode;
}
if (_isfireModeImageNotNull && fireModeSprites != null && fireModeSprites.Length > 0)
{
int spriteIndexForMode = GetSpriteIndexForMode(fireMode);
if (spriteIndexForMode >= 0 && spriteIndexForMode < fireModeSprites.Length)
{
fireModeImage.sprite = fireModeSprites[spriteIndexForMode];
}
}
}
if (EnabledObjects)
{
int num = int.Parse(CalculateAmmoCounterAmount(ammoCount, ref lastAmountOfBulletsForEnableObjects, enableLerpForEnabledObjects, DispLerpAmt));
if (EnableBasedOnPercentage)
{
SetEnabledObjectsPercentage(num);
}
else
{
SetEnabledObjects(num);
}
}
if (enableLowAmmoWarning)
{
UpdateLowAmmoWarning(ammoCount, maxAmmoCount, flag);
}
else
{
ResetWarningState();
}
if (showChamberIndicator)
{
int num2 = 0;
if (chambers != null)
{
num2 = chambers.Count((FVRFireArmChamber chamber) => chamber.IsFull && !chamber.IsSpent);
}
bool flag2 = num2 > 0;
if (chamberIndicatorUseImage)
{
if (_isChamberIndicatorImageNotNull && (Object)(object)chamberIndicatorImage != (Object)null)
{
((Component)chamberIndicatorImage).gameObject.SetActive(flag2);
}
}
else if (_isChamberIndicatorTextNotNull && (Object)(object)chamberIndicatorText != (Object)null)
{
((Component)chamberIndicatorText).gameObject.SetActive(flag2);
if (flag2)
{
chamberIndicatorText.text = chamberIndicatorString;
}
}
}
else
{
if (_isChamberIndicatorImageNotNull && (Object)(object)chamberIndicatorImage != (Object)null)
{
((Component)chamberIndicatorImage).gameObject.SetActive(false);
}
if (_isChamberIndicatorTextNotNull && (Object)(object)chamberIndicatorText != (Object)null)
{
((Component)chamberIndicatorText).gameObject.SetActive(false);
}
}
_previousAmmoCount = ammoCount;
_hadMagLastFrame = flag;
}
private void UpdateLowAmmoWarning(int currentAmmo, int maxAmmo, bool hasMag)
{
if (!hasMag)
{
ResetWarningState();
return;
}
bool flag = hasMag && !_hadMagLastFrame;
bool flag2 = false;
bool flag3 = false;
if (maxAmmo > 0)
{
if (currentAmmo > 0)
{
float num = (float)currentAmmo / (float)maxAmmo * 100f;
flag2 = num <= lowAmmoThresholdPercent;
}
if (_previousAmmoCount > 0)
{
float num2 = (float)_previousAmmoCount / (float)maxAmmo * 100f;
flag3 = num2 <= lowAmmoThresholdPercent;
}
}
if (flag2 && (!flag3 || flag))
{
PlayWarningClip(lowAmmoClip);
}
if (currentAmmo <= 0)
{
bool flag4 = _previousAmmoCount > 0;
bool flag5 = flag;
if ((flag4 || flag5) && !_hasPlayedDepletedSound)
{
PlayWarningClip(depletedAmmoClip);
_hasPlayedDepletedSound = true;
}
}
if (maxAmmo > 0 && currentAmmo > 0)
{
float num3 = (float)currentAmmo / (float)maxAmmo * 100f;
if (num3 > lowAmmoThresholdPercent)
{
_hasPlayedDepletedSound = false;
}
}
if (enableLowAmmoBlink && _isUItextNotNull && (flag2 || _hasPlayedDepletedSound))
{
_isBlinking = true;
_blinkTimer += Time.deltaTime;
float num4 = ((!(blinkRate > 0f)) ? 1f : (1f / blinkRate));
bool enabled = _blinkTimer % num4 < num4 * 0.5f;
((Behaviour)UItext).enabled = enabled;
}
else if (_isBlinking)
{
_isBlinking = false;
_blinkTimer = 0f;
if (_isUItextNotNull)
{
((Behaviour)UItext).enabled = true;
}
}
}
private void ResetWarningState()
{
if (_isBlinking)
{
_isBlinking = false;
_blinkTimer = 0f;
if (_isUItextNotNull)
{
((Behaviour)UItext).enabled = true;
}
}
_hasPlayedLowAmmoSound = false;
_hasPlayedDepletedSound = false;
}
private void PlayWarningClip(AudioClip clip)
{
if ((Object)(object)clip != (Object)null && (Object)(object)warningAudioSource != (Object)null)
{
warningAudioSource.PlayOneShot(clip);
}
}
private int GetAmmoCount()
{
if ((Object)(object)_mag != (Object)null)
{
return _mag.m_numRounds;
}
int num = 0;
if ((Object)(object)_fa != (Object)null)
{
if (chambers != null)
{
num += chambers.Count((FVRFireArmChamber chamber) => chamber.IsFull && !chamber.IsSpent);
}
if (proxies != null)
{
FVRFirearmMovingProxyRound[] array = proxies;
foreach (FVRFirearmMovingProxyRound val in array)
{
if (val.IsFull)
{
num++;
}
}
}
if ((Object)(object)_fa.BeltDD != (Object)null)
{
num += _fa.BeltDD.m_roundsOnBelt;
}
}
return num;
}
private int GetMaxAmmoCount()
{
if ((Object)(object)_mag != (Object)null)
{
return _mag.m_capacity;
}
if ((Object)(object)_fa != (Object)null && !_fa.UsesMagazines)
{
return (chambers != null) ? chambers.Length : 0;
}
return 0;
}
private string GetAmmoType()
{
//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: 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 ((Object)(object)_fa != (Object)null)
{
List<FireArmRoundClass> chamberRoundList = _fa.GetChamberRoundList();
if (chamberRoundList != null && chamberRoundList.Count > 0)
{
return AM.GetFullRoundName(_fa.RoundType, chamberRoundList[0]);
}
if ((Object)(object)_fa.BeltDD != (Object)null && _fa.BeltDD.m_roundsOnBelt > 0)
{
return AM.GetFullRoundName(_fa.RoundType, _fa.BeltDD.BeltRounds[0].LR_Class);
}
}
if ((Object)(object)_mag != (Object)null && _mag.m_numRounds > 0)
{
return AM.GetFullRoundName(_mag.RoundType, _mag.LoadedRounds[0].LR_Class);
}
return string.Empty;
}
private string GetFireMode()
{
if ((Object)(object)_fa == (Object)null)
{
return "N/A";
}
FVRFireArm fa = _fa;
Handgun val = (Handgun)(object)((fa is Handgun) ? fa : null);
if ((Object)(object)val == (Object)null)
{
return "N/A";
}
if (val.IsSafetyEngaged)
{
return "Safe";
}
if (val.FireSelectorModes != null && val.FireSelectorModes.Length > 0)
{
FireSelectorMode val2 = val.FireSelectorModes[val.FireSelectorModeIndex];
return ((object)Unsafe.As<FireSelectorModeType, FireSelectorModeType>(ref val2.ModeType)/*cast due to .constrained prefix*/).ToString();
}
return "N/A";
}
private int GetSpriteIndexForMode(string mode)
{
return mode switch
{
"Safe" => 0,
"Single" => 1,
"FullAuto" => 2,
"Burst" => 3,
_ => 4,
};
}
public static string CalculateAmmoCounterAmount(int currentammo, ref int lastammo, bool lerp = false, float lerpAmt = 0f, bool pad = false, int padAmt = 0)
{
if (lerp)
{
currentammo = LerpInt(lastammo, currentammo, lerpAmt);
}
string text = currentammo.ToString();
if (pad)
{
text = PadStringNumberToAmt(text, padAmt);
}
lastammo = currentammo;
return text;
}
public static string PadStringNumberToAmt(string str, int minCharLength)
{
int num = minCharLength - str.Length;
for (int i = 0; i < num; i++)
{
str = "0" + str;
}
return str;
}
public static int LerpInt(int a, int b, float lerp)
{
bool flag = a == 0;
a = Mathf.CeilToInt(Mathf.Lerp((float)a, (float)b, lerp));
if (a == 1 && flag)
{
a = 0;
}
return a;
}
private void SetEnabledObjects(int amt)
{
amt = Mathf.Clamp(amt, 0, Objects.Count - 1);
for (int i = 0; i < Objects.Count; i++)
{
Objects[i].SetActive(false);
}
if ((Object)(object)ObjectWhenEmpty != (Object)null)
{
ObjectWhenEmpty.SetActive(false);
}
if ((Object)(object)_mag == (Object)null && (Object)(object)ObjectWhenEmpty != (Object)null)
{
ObjectWhenEmpty.SetActive(true);
return;
}
for (int j = 0; j < Objects.Count; j++)
{
if (j < amt)
{
if (EnableAllUnderAmount)
{
Objects[j].SetActive(true);
}
}
else if (j == amt)
{
Objects[j].SetActive(true);
}
}
}
private void SetEnabledObjectsPercentage(int amt)
{
amt = Mathf.Clamp(amt, 0, Objects.Count - 1);
int maxAmmoCount = GetMaxAmmoCount();
if (maxAmmoCount <= 0)
{
return;
}
float num = (float)amt / (float)maxAmmoCount;
for (int i = 0; i < Objects.Count; i++)
{
Objects[i].SetActive(false);
}
if ((Object)(object)ObjectWhenEmpty != (Object)null)
{
ObjectWhenEmpty.SetActive(false);
}
if ((Object)(object)_mag == (Object)null && (Object)(object)ObjectWhenEmpty != (Object)null)
{
ObjectWhenEmpty.SetActive(true);
return;
}
for (int j = 0; j < Objects.Count; j++)
{
float num2 = ObjectPercentages[j] / 100f;
float num3 = 0f;
if (j > 0)
{
num3 = ObjectPercentages[j - 1] / 100f;
}
if (!(num > num2))
{
continue;
}
if (num > num3)
{
if (EnableAllUnderAmount)
{
Objects[j].SetActive(true);
}
}
else
{
Objects[j].SetActive(true);
}
}
}
public void NullCheck()
{
_isammoTypeTextNotNull = (Object)(object)ammoTypeText != (Object)null;
_isMaxAmmoTextNotNull = (Object)(object)MaxAmmoText != (Object)null;
_isUItextNotNull = (Object)(object)UItext != (Object)null;
_isfireModeTextNotNull = (Object)(object)fireModeText != (Object)null;
_isfireModeImageNotNull = (Object)(object)fireModeImage != (Object)null;
_isChamberIndicatorImageNotNull = (Object)(object)chamberIndicatorImage != (Object)null;
_isChamberIndicatorTextNotNull = (Object)(object)chamberIndicatorText != (Object)null;
}
}
public class SimpleCompass : MonoBehaviour
{
[Header("Target")]
[Tooltip("Assign Forward Z for North Facing, I think.")]
public Transform Target;
[Header("Text Version")]
public Text CompassText;
[Header("Image Version")]
[Tooltip("The arrow that will be rotated to indicate which direction.")]
public RectTransform CompassImage;
private void Update()
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)Target == (Object)null))
{
Vector3 forward = Target.forward;
forward.y = 0f;
((Vector3)(ref forward)).Normalize();
float num = Mathf.Atan2(forward.x, forward.z) * 57.29578f;
if (num < 0f)
{
num += 360f;
}
if ((Object)(object)CompassText != (Object)null)
{
CompassText.text = GetCardinalLabel(num) + " " + Mathf.RoundToInt(num) + "°";
}
if ((Object)(object)CompassImage != (Object)null)
{
((Transform)CompassImage).localEulerAngles = new Vector3(0f, 0f, num);
}
}
}
private string GetCardinalLabel(float angle)
{
if (angle < 22.5f || angle >= 337.5f)
{
return "N";
}
if (angle < 67.5f)
{
return "NE";
}
if (angle < 112.5f)
{
return "E";
}
if (angle < 157.5f)
{
return "SE";
}
if (angle < 202.5f)
{
return "S";
}
if (angle < 247.5f)
{
return "SW";
}
if (angle < 292.5f)
{
return "W";
}
return "NW";
}
}