Decompiled source of Cross Fire MG3 Silver Killer v0.1.5

MG3SilverKillerPrototype.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 MG3SilverKiller
{
	public class MG3BeltAmmo : MonoBehaviour
	{
		public FVRFireArmBeltSegment Belt;

		public int Capacity = 20;

		public bool FillOnSpawn = true;

		public Material SilverMaterial;

		private IEnumerator Start()
		{
			if (!FillOnSpawn || (Object)(object)Belt == (Object)null || Belt.RoundList.Count != 0)
			{
				yield break;
			}
			for (int attempt = 0; attempt < 120; attempt++)
			{
				if (TryFill())
				{
					yield break;
				}
				yield return (object)new WaitForSeconds(0.25f);
			}
			Debug.LogError((object)"MG3 Silver Killer: ammunition data unavailable; belt left empty.");
		}

		private bool TryFill()
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				FireArmRoundType val = (FireArmRoundType)16;
				FireArmRoundClass defaultRoundClass = AM.GetDefaultRoundClass(val);
				FVRObject roundSelfPrefab = AM.GetRoundSelfPrefab(val, defaultRoundClass);
				Mesh roundMesh = AM.GetRoundMesh(val, defaultRoundClass);
				Material val2 = ((!((Object)(object)SilverMaterial != (Object)null)) ? AM.GetRoundMaterial(val, defaultRoundClass) : SilverMaterial);
				if ((Object)(object)roundSelfPrefab == (Object)null || (Object)(object)roundMesh == (Object)null || (Object)(object)val2 == (Object)null)
				{
					return false;
				}
				if (Belt.RoundList.Count != 0)
				{
					return true;
				}
				int num = Mathf.Min(Capacity, Belt.ProxyRounds.Count);
				for (int i = 0; i < num; i++)
				{
					List<FVRLoadedRound> roundList = Belt.RoundList;
					FVRLoadedRound val3 = new FVRLoadedRound();
					val3.LR_Class = defaultRoundClass;
					val3.LR_Mesh = roundMesh;
					val3.LR_Material = val2;
					val3.LR_ObjectWrapper = roundSelfPrefab;
					roundList.Add(val3);
				}
				Belt.UpdateBulletDisplay();
				return true;
			}
			catch (NullReferenceException)
			{
				return false;
			}
			catch (KeyNotFoundException)
			{
				return false;
			}
		}
	}
	public class MG3EasyLoadBelt : FVRFireArmBeltSegment
	{
		public static bool CanSeatAt(BoxCollider box, FVRFireArm gun, Vector3 head)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)box == (Object)null || !((Collider)box).enabled || !((Component)box).gameObject.activeInHierarchy || (Object)(object)gun == (Object)null || gun.HasBelt || (gun.UsesTopCover && !gun.IsTopCoverUp))
			{
				return false;
			}
			Vector3 val = ((Component)box).transform.InverseTransformPoint(head) - box.center;
			Vector3 val2 = box.size * 0.5f;
			return Mathf.Abs(val.x) <= val2.x && Mathf.Abs(val.y) <= val2.y && Mathf.Abs(val.z) <= val2.z;
		}

		public override void EndInteraction(FVRViveHand hand)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			if (base.RoundList.Count > 0)
			{
				Collider[] array = Physics.OverlapSphere(((Component)this).transform.position, 0.5f, 1 << LayerMask.NameToLayer("PlayerAndRBTrigger"));
				foreach (Collider val in array)
				{
					MG3SeatDiagnostics component = ((Component)val).GetComponent<MG3SeatDiagnostics>();
					if ((Object)(object)component != (Object)null && CanSeatAt((BoxCollider)(object)((val is BoxCollider) ? val : null), component.Firearm, ((Component)this).transform.position))
					{
						((FVRFireArmBeltSegment)this).OnTriggerEnter(val);
						break;
					}
				}
			}
			((FVRFireArmBeltSegment)this).EndInteraction(hand);
		}
	}
	public class MG3FeedGuide : MonoBehaviour
	{
		public FVRFireArm Firearm;

		public GameObject Guide;

		public bool BeltNearby;

		private Renderer[] renderers;

		private MaterialPropertyBlock colors;

		private void Start()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			renderers = Guide.GetComponentsInChildren<Renderer>();
			colors = new MaterialPropertyBlock();
		}

		private void Update()
		{
			//IL_00ac: 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)
			if ((Object)(object)Guide == (Object)null || (Object)(object)Firearm == (Object)null)
			{
				return;
			}
			Guide.SetActive(Firearm.IsTopCoverUp && !Firearm.HasBelt);
			if (colors != null)
			{
				colors.SetColor("_Color", (!BeltNearby) ? new Color(0.05f, 0.58f, 0.65f, 1f) : new Color(0.12f, 0.8f, 0.2f, 1f));
				Renderer[] array = renderers;
				foreach (Renderer val in array)
				{
					val.SetPropertyBlock(colors);
				}
			}
		}
	}
	public class MG3PhysicsDiagnostics : MonoBehaviour
	{
		private FVRPhysicalObject item;

		private bool held;

		private int remaining = 10;

		private IEnumerator Start()
		{
			item = ((Component)this).GetComponent<FVRPhysicalObject>();
			yield return null;
			Report("spawn");
		}

		private void Update()
		{
			if (!((Object)(object)item == (Object)null) && remaining > 0 && held != ((FVRInteractiveObject)item).IsHeld)
			{
				held = ((FVRInteractiveObject)item).IsHeld;
				Report((!held) ? "release" : "grab");
			}
		}

		private void Report(string phase)
		{
			//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_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)
			remaining--;
			Rigidbody component = ((Component)this).GetComponent<Rigidbody>();
			int num = 0;
			int num2 = 0;
			int num3 = 0;
			Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if (!val.enabled || !((Component)val).gameObject.activeInHierarchy)
				{
					continue;
				}
				if (val.isTrigger)
				{
					num3++;
					continue;
				}
				num++;
				if (!Physics.GetIgnoreLayerCollision(((Component)val).gameObject.layer, LayerMask.NameToLayer("Environment")))
				{
					num2++;
				}
			}
			string text = "";
			MeshFilter[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val2 in componentsInChildren2)
			{
				if ((Object)(object)val2.sharedMesh != (Object)null && (((Object)val2).name == "Receiver" || ((Object)val2).name == "FeedCover" || ((Object)val2).name == "ChargingHandle"))
				{
					string text2 = text;
					string[] obj = new string[5]
					{
						text2,
						" ",
						((Object)val2).name,
						"=",
						null
					};
					Vector3 val3 = ((Component)this).transform.InverseTransformPoint(((Component)val2).transform.position);
					obj[4] = ((Vector3)(ref val3)).ToString("F3");
					text = string.Concat(obj);
				}
			}
			object[] obj2 = new object[17]
			{
				"MG3_PHYSICS_011 ",
				((Object)this).name,
				" ",
				phase,
				" pos=",
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null,
				null
			};
			Vector3 position = ((Component)this).transform.position;
			obj2[5] = ((Vector3)(ref position)).ToString("F3");
			obj2[6] = " rootRB=";
			obj2[7] = (Object)(object)component != (Object)null;
			obj2[8] = " rigidbodies=";
			obj2[9] = ((Component)this).GetComponentsInChildren<Rigidbody>(true).Length;
			obj2[10] = " solid/world/trigger=";
			obj2[11] = num;
			obj2[12] = "/";
			obj2[13] = num2;
			obj2[14] = "/";
			obj2[15] = num3;
			obj2[16] = text;
			Debug.Log((object)string.Concat(obj2));
		}
	}
	public class MG3SeatDiagnostics : MonoBehaviour
	{
		public FVRFireArm Firearm;

		public MG3FeedGuide Guide;

		private readonly HashSet<Collider> nearby = new HashSet<Collider>();

		private int reports;

		private void OnTriggerEnter(Collider c)
		{
			FVRFireArmBeltSegment componentInParent = ((Component)c).GetComponentInParent<FVRFireArmBeltSegment>();
			if (!((Object)(object)componentInParent == (Object)null))
			{
				nearby.Add(c);
				if (reports++ < 12)
				{
					Debug.Log((object)("MG3_SEAT_012 enter rounds=" + componentInParent.RoundList.Count + " coverOpen=" + Firearm.IsTopCoverUp + " hasBelt=" + Firearm.HasBelt));
				}
			}
		}

		private void OnTriggerExit(Collider c)
		{
			nearby.Remove(c);
		}

		private void Update()
		{
			nearby.RemoveWhere((Collider c) => (Object)(object)c == (Object)null || !c.enabled || !((Component)c).gameObject.activeInHierarchy);
			Guide.BeltNearby = nearby.Count > 0;
		}
	}
}
namespace LocalTest.MG3SilverKillerPrototype
{
	[BepInPlugin("LocalTest.MG3SilverKillerPrototype", "MG3SilverKillerPrototype", "0.1.4")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class MG3SilverKillerPrototypePlugin : 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.MG3SilverKillerPrototype");
			OtherLoader.RegisterDirectLoad(BasePath, "LocalTest.MG3SilverKillerPrototype", "", "", "mg3_silver_killer", "");
		}
	}
}