Decompiled source of NZ Storm Dragon v0.1.3

StormDragonPrototype.dll

Decompiled an hour ago
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 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 LocalTest.StormDragonPrototype
{
	[BepInPlugin("LocalTest.StormDragonPrototype", "StormDragonPrototype", "0.1.2")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class StormDragonPrototypePlugin : 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(), "LocalTest.StormDragonPrototype");
			OtherLoader.RegisterDirectLoad(BasePath, "LocalTest.StormDragonPrototype", "", "", "storm_dragon", "");
		}
	}
}
namespace StormDragon
{
	[Serializable]
	public class SixRoundState
	{
		public int index;

		public int[] classes = new int[6] { 70, 70, 70, 70, 70, 70 };

		public bool[] spent = new bool[6];

		public bool CanFire => classes != null && classes.Length == 6 && spent != null && spent.Length == 6 && index >= 0 && index < 6 && classes[index] >= 0 && !spent[index];

		public int Remaining
		{
			get
			{
				int num = 0;
				for (int i = 0; i < 6; i++)
				{
					if (classes[i] >= 0 && !spent[i])
					{
						num++;
					}
				}
				return num;
			}
		}

		public bool AdvanceAfterShot()
		{
			if (!CanFire)
			{
				return false;
			}
			spent[index] = true;
			index = (index + 1) % 6;
			return true;
		}
	}
	public class StormCylinder : FVRPhysicalObject
	{
		private struct Pair
		{
			public Collider a;

			public Collider b;
		}

		public Transform Rotor;

		public Transform[] ChamberSlots;

		public FVRFireArmChamber[] Chambers = (FVRFireArmChamber[])(object)new FVRFireArmChamber[6];

		public StormLauncher Launcher;

		public SixRoundState State = new SixRoundState();

		public bool Ready;

		public float Angle;

		private readonly List<Pair> pairs = new List<Pair>();

		public bool Busy => Mathf.Abs(Angle - (float)State.index * 60f) > 0.05f;

		public override void Start()
		{
			((FVRInteractiveObject)this).Start();
			((MonoBehaviour)this).StartCoroutine(Initialize());
		}

		private IEnumerator Initialize()
		{
			yield return StormResources.Load();
			if ((Object)(object)StormResources.M203Prefab == (Object)null)
			{
				yield break;
			}
			FVRFireArmChamber template = StormResources.M203Prefab.GetComponent<M203>().Chamber;
			for (int i = 0; i < 6; i++)
			{
				GameObject val = Object.Instantiate<GameObject>(((Component)template).gameObject);
				((Object)val).name = "Native 40mm chamber " + i;
				val.transform.SetParent(ChamberSlots[i], false);
				val.transform.localPosition = Vector3.zero;
				val.transform.localRotation = Quaternion.identity;
				Chambers[i] = val.GetComponent<FVRFireArmChamber>();
				Chambers[i].RoundType = (FireArmRoundType)23;
				Chambers[i].IsManuallyChamberable = false;
				Chambers[i].IsManuallyExtractable = false;
				Chambers[i].IsAccessible = false;
				Chambers[i].SuppressProxyVisibility = true;
				Chambers[i].OverrideAudioSet = StormResources.GrenadeAudio;
				Collider[] componentsInChildren = val.GetComponentsInChildren<Collider>(true);
				foreach (Collider val2 in componentsInChildren)
				{
					val2.enabled = false;
				}
			}
			yield return null;
			for (int k = 0; k < 6; k++)
			{
				if (State.classes[k] >= 0)
				{
					FVRFireArmChamber val3 = Chambers[k];
					val3.SetRound((FireArmRoundClass)State.classes[k], ((Component)val3).transform.position, ((Component)val3).transform.rotation);
					if (State.spent[k])
					{
						val3.IsSpent = true;
						val3.UpdateProxyDisplay();
					}
				}
			}
			Ready = true;
			SnapRotation();
			FitProxies();
		}

		public void FitProxies()
		{
			FVRFireArmChamber[] chambers = Chambers;
			foreach (FVRFireArmChamber val in chambers)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.SuppressProxyVisibility = true;
					if ((Object)(object)val.ProxyRound != (Object)null)
					{
						((Component)val.ProxyRound).gameObject.SetActive(false);
					}
				}
			}
		}

		public override void FVRUpdate()
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			((FVRPhysicalObject)this).FVRUpdate();
			if (!((Object)(object)Rotor == (Object)null))
			{
				float num = (float)State.index * 60f;
				float num2 = Mathf.DeltaAngle(Angle, num);
				Angle += Mathf.Clamp(num2, -500f * Time.deltaTime, 500f * Time.deltaTime);
				if (Mathf.Abs(Mathf.DeltaAngle(Angle, num)) < 0.05f)
				{
					Angle = num;
				}
				Rotor.localRotation = Quaternion.Euler(0f, 0f, Angle);
				FitProxies();
			}
		}

		public void SnapRotation()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			Angle = (float)State.index * 60f;
			if ((Object)(object)Rotor != (Object)null)
			{
				Rotor.localRotation = Quaternion.Euler(0f, 0f, Angle);
			}
		}

		public bool CommitShot()
		{
			if (!State.AdvanceAfterShot())
			{
				return false;
			}
			return true;
		}

		public override void BeginInteraction(FVRViveHand hand)
		{
			if ((Object)(object)Launcher != (Object)null)
			{
				Launcher.ReleaseCylinder(this);
			}
			((FVRPhysicalObject)this).BeginInteraction(hand);
		}

		public void AttachTo(StormLauncher owner)
		{
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			((FVRInteractiveObject)this).ForceBreakInteraction();
			Launcher = owner;
			Collider[] componentsInChildren = ((Component)owner.Firearm).GetComponentsInChildren<Collider>(true);
			Collider[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<Collider>(true);
			Collider[] array = componentsInChildren2;
			foreach (Collider val in array)
			{
				Collider[] array2 = componentsInChildren;
				foreach (Collider val2 in array2)
				{
					if (!((Object)(object)val == (Object)null) && !((Object)(object)val2 == (Object)null) && !((Object)(object)val == (Object)(object)val2) && !val.isTrigger && !val2.isTrigger && !((Component)val2).transform.IsChildOf(((Component)this).transform))
					{
						Physics.IgnoreCollision(val, val2, true);
						pairs.Add(new Pair
						{
							a = val,
							b = val2
						});
					}
				}
			}
			Rigidbody component = ((Component)this).GetComponent<Rigidbody>();
			component.isKinematic = true;
			component.useGravity = false;
			((Component)this).transform.SetParent(owner.Socket, false);
			((Component)this).transform.localPosition = Vector3.zero;
			((Component)this).transform.localRotation = Quaternion.identity;
			SnapRotation();
		}

		public void Detach()
		{
			Launcher = null;
			((Component)this).transform.SetParent((Transform)null, true);
			Rigidbody component = ((Component)this).GetComponent<Rigidbody>();
			component.isKinematic = false;
			component.useGravity = true;
			((MonoBehaviour)this).StartCoroutine(RestoreContacts());
		}

		private IEnumerator RestoreContacts()
		{
			yield return (object)new WaitForSeconds(0.2f);
			if ((Object)(object)Launcher == (Object)null)
			{
				RestorePairs();
			}
		}

		private void RestorePairs()
		{
			foreach (Pair pair in pairs)
			{
				if ((Object)(object)pair.a != (Object)null && (Object)(object)pair.b != (Object)null)
				{
					Physics.IgnoreCollision(pair.a, pair.b, false);
				}
			}
			pairs.Clear();
		}

		public override void OnDestroy()
		{
			RestorePairs();
			if ((Object)(object)Launcher != (Object)null && (Object)(object)Launcher.Cylinder == (Object)(object)this)
			{
				Launcher.Cylinder = null;
			}
			((FVRPhysicalObject)this).OnDestroy();
		}

		public string ExportState()
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (Ready)
			{
				for (int i = 0; i < 6; i++)
				{
					FVRFireArmChamber val = Chambers[i];
					if (!((Object)(object)val == (Object)null))
					{
						State.classes[i] = ((!val.IsFull || !((Object)(object)val.GetRound() != (Object)null)) ? (-1) : ((int)val.GetRound().RoundClass));
						State.spent[i] = val.IsSpent;
					}
				}
			}
			return JsonUtility.ToJson((object)State);
		}

		public void ImportState(string value)
		{
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			SixRoundState sixRoundState = JsonUtility.FromJson<SixRoundState>(value);
			if (sixRoundState == null || sixRoundState.classes == null || sixRoundState.classes.Length != 6 || sixRoundState.spent == null || sixRoundState.spent.Length != 6 || sixRoundState.index < 0 || sixRoundState.index >= 6)
			{
				throw new Exception("Invalid six-round cylinder state");
			}
			State = sixRoundState;
			SnapRotation();
			if (!Ready)
			{
				return;
			}
			for (int i = 0; i < 6; i++)
			{
				FVRFireArmChamber val = Chambers[i];
				val.SetRound((FVRFireArmRound)null, false);
				if (State.classes[i] >= 0)
				{
					val.SetRound((FireArmRoundClass)State.classes[i], ((Component)val).transform.position, ((Component)val).transform.rotation);
					val.IsSpent = State.spent[i];
					val.UpdateProxyDisplay();
				}
			}
		}

		public override Dictionary<string, string> GetFlagDic()
		{
			Dictionary<string, string> dictionary = ((FVRPhysicalObject)this).GetFlagDic() ?? new Dictionary<string, string>();
			dictionary["StormSix"] = ExportState();
			return dictionary;
		}

		public override void ConfigureFromFlagDic(Dictionary<string, string> flags)
		{
			((FVRPhysicalObject)this).ConfigureFromFlagDic(flags);
			if (flags.TryGetValue("StormSix", out var value))
			{
				ImportState(value);
			}
		}
	}
	public class StormCylinderSocket : MonoBehaviour
	{
		public StormLauncher Launcher;

		private void OnTriggerStay(Collider c)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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)
			Rigidbody attachedRigidbody = c.attachedRigidbody;
			StormCylinder stormCylinder = ((!((Object)(object)attachedRigidbody == (Object)null)) ? ((Component)attachedRigidbody).GetComponent<StormCylinder>() : null);
			if (!((Object)(object)stormCylinder == (Object)null) && ((FVRInteractiveObject)stormCylinder).IsHeld && !((Object)(object)stormCylinder.Launcher != (Object)null) && !(Vector3.Distance(((Component)stormCylinder).transform.position, Launcher.Socket.position) > 0.045f) && !(Vector3.Dot(((Component)stormCylinder).transform.forward, Launcher.Socket.forward) < 0.9f))
			{
				Launcher.InstallCylinder(stormCylinder);
			}
		}
	}
	public class StormLauncher : MonoBehaviour
	{
		public ClosedBoltWeapon Firearm;

		public FVRFireArmAttachmentMount Mount;

		public Transform Socket;

		public Transform Muzzle;

		public StormCylinder Cylinder;

		public M203 Backend;

		public bool Ready;

		public string RestoreState;

		private float lastFire = -10f;

		private IEnumerator Start()
		{
			yield return StormResources.Load();
			if ((Object)(object)StormResources.M203Prefab == (Object)null)
			{
				yield break;
			}
			AttachableFirearmPhysicalObject attachment = null;
			foreach (FVRFireArmAttachment attachments in Mount.AttachmentsList)
			{
				if ((Object)(object)((FVRPhysicalObject)attachments).ObjectWrapper != (Object)null && ((FVRPhysicalObject)attachments).ObjectWrapper.ItemID == "M203Picatinny")
				{
					attachment = (AttachableFirearmPhysicalObject)(object)((attachments is AttachableFirearmPhysicalObject) ? attachments : null);
					break;
				}
			}
			if ((Object)(object)attachment == (Object)null)
			{
				attachment = Object.Instantiate<GameObject>(StormResources.M203Prefab).GetComponent<AttachableFirearmPhysicalObject>();
				((Component)attachment).gameObject.SetActive(true);
				((Component)attachment).transform.position = ((Component)Mount).transform.position;
				((Component)attachment).transform.rotation = ((Component)Mount).transform.rotation;
				((FVRFireArmAttachment)attachment).AttachToMount(Mount, false);
			}
			Backend = ((Component)attachment).GetComponent<M203>();
			((AttachableFirearm)Backend).OverrideFA = (FVRFireArm)(object)Firearm;
			((AttachableFirearm)Backend).AudioClipSet = StormResources.GrenadeAudio;
			((AttachableFirearm)Backend).RecoilProfile = StormResources.GrenadeRecoil;
			Renderer[] componentsInChildren = ((Component)attachment).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				val.enabled = false;
			}
			Collider[] componentsInChildren2 = ((Component)attachment).GetComponentsInChildren<Collider>(true);
			foreach (Collider val2 in componentsInChildren2)
			{
				val2.enabled = false;
			}
			((AttachableFirearm)Backend).MuzzlePos = Muzzle;
			((AttachableFirearm)Backend).CurrentMuzzle = Muzzle;
			Ready = true;
			if (!string.IsNullOrEmpty(RestoreState))
			{
				yield return RestoreCylinder();
			}
			Debug.Log((object)"STORM_SIX_LAUNCHER_READY: native 40mm HE and MGL audio");
		}

		public bool InstallCylinder(StormCylinder pack)
		{
			if (!Ready || (Object)(object)Cylinder != (Object)null || (Object)(object)pack == (Object)null || !pack.Ready || (Object)(object)pack.Launcher != (Object)null)
			{
				return false;
			}
			Cylinder = pack;
			pack.AttachTo(this);
			FVRFireArmChamber[] chambers = pack.Chambers;
			foreach (FVRFireArmChamber val in chambers)
			{
				if ((Object)(object)val != (Object)null)
				{
					val.Firearm = (FVRFireArm)(object)Firearm;
				}
			}
			((AttachableFirearm)Backend).PlayAudioEvent((FirearmAudioEventType)18, 1f);
			return true;
		}

		public void ReleaseCylinder(StormCylinder pack)
		{
			if (!((Object)(object)Cylinder != (Object)(object)pack))
			{
				Cylinder = null;
				pack.Detach();
				if (Ready)
				{
					((AttachableFirearm)Backend).PlayAudioEvent((FirearmAudioEventType)17, 1f);
				}
			}
		}

		public bool TryFire()
		{
			if (!Ready || (Object)(object)Cylinder == (Object)null || !Cylinder.Ready || Cylinder.Busy || !Cylinder.State.CanFire || Time.time - lastFire < 0.22f)
			{
				return false;
			}
			FVRFireArmChamber val = Cylinder.Chambers[Cylinder.State.index];
			if ((Object)(object)val == (Object)null || !val.IsFull || val.IsSpent)
			{
				return false;
			}
			val.Firearm = (FVRFireArm)(object)Firearm;
			Backend.Chamber = val;
			((AttachableFirearm)Backend).MuzzlePos = Muzzle;
			((AttachableFirearm)Backend).CurrentMuzzle = Muzzle;
			Backend.Fire(true);
			if (!val.IsSpent)
			{
				return false;
			}
			lastFire = Time.time;
			bool flag = Cylinder.CommitShot();
			if (flag)
			{
				((AttachableFirearm)Backend).PlayAudioEvent((FirearmAudioEventType)16, 1f);
			}
			return flag;
		}

		private IEnumerator RestoreCylinder()
		{
			if (!IM.OD.TryGetValue("StormDragonCylinder6", out var entry))
			{
				yield break;
			}
			AnvilCallback<GameObject> request = ((AnvilAsset)entry).GetGameObjectAsync();
			yield return request;
			if ((Object)(object)request.Result == (Object)null)
			{
				yield break;
			}
			StormCylinder pack = Object.Instantiate<GameObject>(request.Result).GetComponent<StormCylinder>();
			pack.ImportState(RestoreState);
			for (int i = 0; i < 600; i++)
			{
				if (pack.Ready)
				{
					break;
				}
				yield return null;
			}
			if (!InstallCylinder(pack))
			{
				Object.Destroy((Object)(object)((Component)pack).gameObject);
			}
			RestoreState = null;
		}

		private void OnDestroy()
		{
			if ((Object)(object)Mount == (Object)null)
			{
				return;
			}
			FVRFireArmAttachment[] array = Mount.AttachmentsList.ToArray();
			foreach (FVRFireArmAttachment val in array)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)((FVRPhysicalObject)val).ObjectWrapper != (Object)null && ((FVRPhysicalObject)val).ObjectWrapper.ItemID == "M203Picatinny")
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
		}
	}
	public class StormLauncherGrip : FVRInteractiveObject
	{
		public StormLauncher Launcher;

		private bool armed;

		public override void BeginInteraction(FVRViveHand hand)
		{
			((FVRInteractiveObject)this).BeginInteraction(hand);
			armed = hand.Input.TriggerFloat < 0.15f;
		}

		public bool StepTrigger(bool held, bool released, bool down)
		{
			if (!held)
			{
				armed = false;
				return false;
			}
			if (released)
			{
				armed = true;
			}
			if (!down || !armed)
			{
				return false;
			}
			armed = false;
			return true;
		}

		public override void UpdateInteraction(FVRViveHand hand)
		{
			((FVRInteractiveObject)this).UpdateInteraction(hand);
			if (StepTrigger(((FVRInteractiveObject)this).IsHeld, hand.Input.TriggerFloat < 0.15f, hand.Input.TriggerDown))
			{
				Launcher.TryFire();
			}
		}

		public override void EndInteraction(FVRViveHand hand)
		{
			armed = false;
			((FVRInteractiveObject)this).EndInteraction(hand);
		}
	}
	public class StormMagazine : FVRFireArmMagazine
	{
		public GameObject SourceShellStack;

		public void SyncShells()
		{
			if ((Object)(object)SourceShellStack != (Object)null && SourceShellStack.activeSelf != base.m_numRounds > 0)
			{
				SourceShellStack.SetActive(base.m_numRounds > 0);
			}
		}

		public override void FVRUpdate()
		{
			((FVRFireArmMagazine)this).FVRUpdate();
			SyncShells();
		}

		public override void Awake()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_0024: Expected I4, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			FireArmRoundClass[] array = (FireArmRoundClass[])(object)new FireArmRoundClass[base.m_capacity];
			FireArmRoundClass defaultRoundClass = AM.GetDefaultRoundClass(base.RoundType);
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = (FireArmRoundClass)(int)defaultRoundClass;
			}
			FVRMagazineLoadingPattern val = new FVRMagazineLoadingPattern();
			val.Classes = array;
			base.DefaultLoadingPattern = val;
			((FVRFireArmMagazine)this).Awake();
		}
	}
	public class StormNativeAudio : MonoBehaviour
	{
		public ClosedBoltWeapon Firearm;

		public static void ApplyHandling(FVRFirearmAudioSet set, FVRFirearmAudioSet donor)
		{
			set.BoltSlideBackHeld = donor.BoltSlideBackHeld;
			set.BoltSlideForwardHeld = donor.BoltSlideForwardHeld;
			set.HandleBack = donor.HandleBack;
			set.HandleForward = donor.HandleForward;
			set.FireSelector = donor.FireSelector;
			set.MagazineIn = donor.MagazineIn;
			set.MagazineOut = donor.MagazineOut;
			set.MagazineInsertRound = donor.MagazineInsertRound;
			set.MagazineEjectRound = donor.MagazineEjectRound;
		}

		private IEnumerator Start()
		{
			FVRObject entry = null;
			for (int i = 0; i < 300; i++)
			{
				if (IM.OD != null && IM.OD.TryGetValue("Saiga12k", out entry))
				{
					break;
				}
				yield return null;
			}
			if ((Object)(object)entry == (Object)null)
			{
				Debug.LogError((object)"FAL_AUDIO_DONOR_UNAVAILABLE");
				yield break;
			}
			AnvilCallback<GameObject> request = ((AnvilAsset)entry).GetGameObjectAsync();
			yield return request;
			if ((Object)(object)request.Result == (Object)null)
			{
				yield break;
			}
			ClosedBoltWeapon donor = request.Result.GetComponent<ClosedBoltWeapon>();
			if ((Object)(object)donor == (Object)null)
			{
				yield break;
			}
			foreach (FVRObject compatibleMagazine in ((FVRPhysicalObject)donor).ObjectWrapper.CompatibleMagazines)
			{
				if ((Object)(object)compatibleMagazine != (Object)null && !((FVRPhysicalObject)Firearm).ObjectWrapper.CompatibleMagazines.Contains(compatibleMagazine))
				{
					((FVRPhysicalObject)Firearm).ObjectWrapper.CompatibleMagazines.Add(compatibleMagazine);
				}
			}
			ApplyHandling(((FVRFireArm)Firearm).AudioClipSet, ((FVRFireArm)donor).AudioClipSet);
			Debug.Log((object)"STORM_HANDLING_AUDIO_READY: native Saiga handling and magazine events");
		}
	}
	public class StormReflex : MonoBehaviour
	{
		public Transform Muzzle;

		public Transform Window;

		public float ConvergenceDistance = 25f;

		private MaterialPropertyBlock properties;

		public void UpdateAim()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_009c: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			if (!((Object)(object)Muzzle == (Object)null) && !((Object)(object)Window == (Object)null))
			{
				Vector3 val = Muzzle.position + Muzzle.forward * ConvergenceDistance;
				Window.rotation = Quaternion.LookRotation(val - Window.position, ((Component)this).transform.up);
				if (properties == null)
				{
					properties = new MaterialPropertyBlock();
				}
				properties.SetFloat("_ZeroDistance", Vector3.Distance(val, Window.position));
				((Component)Window).GetComponent<Renderer>().SetPropertyBlock(properties);
			}
		}

		private void LateUpdate()
		{
			UpdateAim();
		}
	}
	public static class StormResources
	{
		public static GameObject M203Prefab;

		public static FVRFirearmAudioSet GrenadeAudio;

		public static FVRFireArmRecoilProfile GrenadeRecoil;

		public static IEnumerator Load()
		{
			if ((Object)(object)M203Prefab != (Object)null && (Object)(object)GrenadeAudio != (Object)null)
			{
				yield break;
			}
			FVRObject m203 = null;
			FVRObject mgl = null;
			for (int i = 0; i < 600; i++)
			{
				if (IM.OD != null && IM.OD.TryGetValue("M203Picatinny", out m203) && IM.OD.TryGetValue("MGLGrenadeLauncher", out mgl))
				{
					break;
				}
				yield return null;
			}
			if ((Object)(object)m203 == (Object)null || (Object)(object)mgl == (Object)null)
			{
				Debug.LogError((object)"STORM_NATIVE_GRENADE_RESOURCES_MISSING");
				yield break;
			}
			AnvilCallback<GameObject> a = ((AnvilAsset)m203).GetGameObjectAsync();
			yield return a;
			AnvilCallback<GameObject> b = ((AnvilAsset)mgl).GetGameObjectAsync();
			yield return b;
			if (!((Object)(object)a.Result == (Object)null) && !((Object)(object)b.Result == (Object)null))
			{
				M203Prefab = a.Result;
				FVRFireArm donor = b.Result.GetComponent<FVRFireArm>();
				GrenadeAudio = donor.AudioClipSet;
				GrenadeRecoil = donor.RecoilProfile;
			}
		}
	}
	public class StormShotgun : ClosedBoltWeapon
	{
		public override Dictionary<string, string> GetFlagDic()
		{
			Dictionary<string, string> dictionary = ((ClosedBoltWeapon)this).GetFlagDic() ?? new Dictionary<string, string>();
			StormLauncher component = ((Component)this).GetComponent<StormLauncher>();
			if ((Object)(object)component != (Object)null && (Object)(object)component.Cylinder != (Object)null)
			{
				dictionary["StormMountedCylinder"] = component.Cylinder.ExportState();
			}
			return dictionary;
		}

		public override void ConfigureFromFlagDic(Dictionary<string, string> flags)
		{
			((ClosedBoltWeapon)this).ConfigureFromFlagDic(flags);
			StormLauncher component = ((Component)this).GetComponent<StormLauncher>();
			if ((Object)(object)component != (Object)null && flags.TryGetValue("StormMountedCylinder", out var value))
			{
				component.RestoreState = value;
			}
		}
	}
}

StormMagazineAudio.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using FistVR;
using HarmonyLib;
using UnityEngine;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace StormDragon;

[BepInPlugin("localtest.stormdragon.magazineaudio", "Storm Dragon Magazine Audio", "0.1.3")]
public sealed class StormMagazineAudio : BaseUnityPlugin
{
	private static AudioEvent insertion;

	private static AudioEvent removal;

	private void Awake()
	{
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Expected O, but got Unknown
		string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "audio");
		insertion = Read(Path.Combine(path, "StormClientMagazineIn.wav"));
		removal = Read(Path.Combine(path, "StormClientMagazineOut.wav"));
		MethodInfo methodInfo = AccessTools.Method(typeof(FVRFireArm), "PlayAudioEvent", new Type[2]
		{
			typeof(FirearmAudioEventType),
			typeof(float)
		}, (Type[])null);
		MethodInfo method = typeof(StormMagazineAudio).GetMethod("BeforeEvent", BindingFlags.Static | BindingFlags.NonPublic);
		new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID).Patch((MethodBase)methodInfo, new HarmonyMethod(method), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	private static void BeforeEvent(FVRFireArm __instance, FirearmAudioEventType __0)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Invalid comparison between Unknown and I4
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Invalid comparison between Unknown and I4
		if (((int)__0 == 20 || (int)__0 == 21) && !((Object)(object)((FVRPhysicalObject)__instance).ObjectWrapper == (Object)null) && !(((FVRPhysicalObject)__instance).ObjectWrapper.ItemID != "StormDragon"))
		{
			StormMagazineAudioBinding stormMagazineAudioBinding = ((Component)__instance).GetComponent<StormMagazineAudioBinding>();
			if ((Object)(object)stormMagazineAudioBinding == (Object)null)
			{
				stormMagazineAudioBinding = ((Component)__instance).gameObject.AddComponent<StormMagazineAudioBinding>();
			}
			stormMagazineAudioBinding.Bind(__instance, insertion, removal);
		}
	}

	private static AudioEvent Read(string path)
	{
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ea: Expected O, but got Unknown
		//IL_0205: 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_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: 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)
		byte[] array = null;
		using (BinaryReader binaryReader = new BinaryReader(File.OpenRead(path)))
		{
			if (new string(binaryReader.ReadChars(4)) != "RIFF")
			{
				throw new IOException(path);
			}
			binaryReader.ReadUInt32();
			if (new string(binaryReader.ReadChars(4)) != "WAVE")
			{
				throw new IOException(path);
			}
			while (binaryReader.BaseStream.Position + 8 <= binaryReader.BaseStream.Length)
			{
				string text = new string(binaryReader.ReadChars(4));
				int num = binaryReader.ReadInt32();
				long num2 = binaryReader.BaseStream.Position + num;
				if (num < 0 || num2 > binaryReader.BaseStream.Length)
				{
					throw new IOException(path);
				}
				if (text == "fmt ")
				{
					if (num < 16 || binaryReader.ReadUInt16() != 1 || binaryReader.ReadUInt16() != 1 || binaryReader.ReadInt32() != 22050)
					{
						throw new IOException(path);
					}
					binaryReader.ReadUInt32();
					binaryReader.ReadUInt16();
					if (binaryReader.ReadUInt16() != 16)
					{
						throw new IOException(path);
					}
				}
				if (text == "data")
				{
					array = binaryReader.ReadBytes(num);
				}
				binaryReader.BaseStream.Position = num2 + (num & 1);
			}
		}
		if (array == null || array.Length % 2 != 0)
		{
			throw new IOException(path);
		}
		float[] array2 = new float[array.Length / 2];
		for (int i = 0; i < array2.Length; i++)
		{
			array2[i] = (float)BitConverter.ToInt16(array, i * 2) / 32768f;
		}
		AudioClip val = AudioClip.Create(Path.GetFileNameWithoutExtension(path), array2.Length, 1, 22050, false);
		val.SetData(array2, 0);
		((Object)val).hideFlags = (HideFlags)32;
		AudioEvent val2 = new AudioEvent();
		val2.Clips = new List<AudioClip> { val };
		val2.VolumeRange = Vector2.one;
		val2.PitchRange = Vector2.one;
		val2.ClipLengthRange = Vector2.one;
		return val2;
	}
}
public sealed class StormMagazineAudioBinding : MonoBehaviour
{
	private FVRFirearmAudioSet profile;

	public void Bind(FVRFireArm firearm, AudioEvent insertion, AudioEvent removal)
	{
		if ((Object)(object)profile == (Object)null || (Object)(object)firearm.AudioClipSet != (Object)(object)profile)
		{
			if ((Object)(object)profile != (Object)null)
			{
				Object.Destroy((Object)(object)profile);
			}
			profile = Object.Instantiate<FVRFirearmAudioSet>(firearm.AudioClipSet);
			firearm.AudioClipSet = profile;
		}
		profile.MagazineIn = insertion;
		profile.MagazineOut = removal;
	}

	private void OnDestroy()
	{
		if ((Object)(object)profile != (Object)null)
		{
			Object.Destroy((Object)(object)profile);
		}
	}
}