Decompiled source of Cross Fire Barrett Destruction v0.1.4

BarrettDestructionPrototype.dll

Decompiled an hour ago
using System;
using System.Collections;
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 BarrettDestruction
{
	public class HMMagazineAmmo : FVRFireArmMagazine
	{
		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 HMNativeScope : MonoBehaviour
	{
		public ClosedBoltWeapon Firearm;

		public FVRFireArmAttachmentMount Mount;

		public const string ScopeID = "ScopeClassic3-12x42mm";

		public bool Ready;

		private IEnumerator Start()
		{
			yield return null;
			FVRObject entry = null;
			for (int i = 0; i < 300; i++)
			{
				if (IM.OD != null && IM.OD.TryGetValue("ScopeClassic3-12x42mm", out entry))
				{
					break;
				}
				yield return null;
			}
			if ((Object)(object)entry == (Object)null)
			{
				Debug.LogError((object)"HM_SCOPE_FAILED: native optic ID unavailable");
				yield break;
			}
			AnvilCallback<GameObject> request = ((AnvilAsset)entry).GetGameObjectAsync();
			yield return request;
			try
			{
				FVRFireArmAttachment val = null;
				foreach (FVRFireArmAttachment attachments in Mount.AttachmentsList)
				{
					if ((Object)(object)((FVRPhysicalObject)attachments).ObjectWrapper != (Object)null && ((FVRPhysicalObject)attachments).ObjectWrapper.ItemID == "ScopeClassic3-12x42mm")
					{
						val = attachments;
						break;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					GameObject result = request.Result;
					if ((Object)(object)result == (Object)null)
					{
						throw new Exception("Native scope prefab unavailable");
					}
					val = Object.Instantiate<GameObject>(result).GetComponent<FVRFireArmAttachment>();
					((Component)val).gameObject.SetActive(true);
					((Component)val).transform.position = ((Component)Mount).transform.position;
					((Component)val).transform.rotation = ((Component)Mount).transform.rotation;
					val.AttachToMount(Mount, false);
				}
				Configure(val);
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("HM_SCOPE_FAILED: " + ex));
			}
		}

		public void Configure(FVRFireArmAttachment attachment)
		{
			//IL_0055: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			PIPScopeController componentInChildren = ((Component)attachment).GetComponentInChildren<PIPScopeController>(true);
			if ((Object)(object)componentInChildren == (Object)null || (Object)(object)componentInChildren.PScope == (Object)null)
			{
				throw new Exception("Native PIP controller missing");
			}
			PIPScope pScope = componentInChildren.PScope;
			((Component)attachment).transform.SetParent(((Component)Mount).transform, false);
			((Component)attachment).transform.localPosition = Vector3.zero;
			((Component)attachment).transform.localRotation = Quaternion.identity;
			((Component)attachment).transform.localScale = Vector3.one * 1.105f;
			Renderer[] componentsInChildren = ((Component)attachment).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				val.enabled = (Object)(object)val == (Object)(object)pScope.lensRenderer || (Object)(object)val == (Object)(object)pScope.frontLensRenderer;
			}
			pScope.ocularLensDiameter = 0.046f;
			pScope.frontLensDiameter = 0.061f;
			pScope.objectiveLensDiameter = 0.061f;
			((Component)pScope.lensRenderer).transform.localScale = Vector3.one * 1.2777778f;
			if ((Object)(object)pScope.frontLensRenderer != (Object)null)
			{
				((Component)pScope.frontLensRenderer).transform.localScale = Vector3.one * 1.452381f;
			}
			componentInChildren.OverrideFireArm = (FVRFireArm)(object)Firearm;
			componentInChildren.OverrideMuzzle = ((FVRFireArm)Firearm).MuzzlePos;
			((FVRFireArmAttachmentInterface)componentInChildren).IsLocked = true;
			((FVRFireArmAttachmentInterface)componentInChildren).ForceInteractable = true;
			Collider[] componentsInChildren2 = ((Component)attachment).GetComponentsInChildren<Collider>(true);
			foreach (Collider val2 in componentsInChildren2)
			{
				bool enabled = (Object)(object)((Component)val2).GetComponent<PIPScopeController>() != (Object)null || (Object)(object)((Component)val2).GetComponent<PIPScopeInteraction>() != (Object)null || (Object)(object)((Component)val2).GetComponent<PIPScopeMagnificationInteraction>() != (Object)null;
				val2.enabled = enabled;
			}
			if (Application.isPlaying)
			{
				componentInChildren.UpdateScopeParams();
			}
			Ready = true;
			Debug.Log((object)("HM_SCOPE_READY: native Classic 3-12x42mm; magnifications=" + componentInChildren.MagnificationValues.Count + "; firearm=" + ((FVRPhysicalObject)Firearm).ObjectWrapper.ItemID));
		}

		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.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
		}
	}
}
namespace LocalTest.BarrettDestructionPrototype
{
	[BepInPlugin("LocalTest.BarrettDestructionPrototype", "BarrettDestructionPrototype", "0.1.3")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class BarrettDestructionPrototypePlugin : 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.BarrettDestructionPrototype");
			OtherLoader.RegisterDirectLoad(BasePath, "LocalTest.BarrettDestructionPrototype", "", "", "barrett_destruction", "");
		}
	}
}