Decompiled source of NZ Nether Poison King v0.1.2

NetherPoisonKingPrototype.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.NetherPoisonKingPrototype
{
	[BepInPlugin("LocalTest.NetherPoisonKingPrototype", "NetherPoisonKingPrototype", "0.1.1")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class NetherPoisonKingPrototypePlugin : 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.NetherPoisonKingPrototype");
			OtherLoader.RegisterDirectLoad(BasePath, "LocalTest.NetherPoisonKingPrototype", "", "", "nz_poison_king", "");
		}
	}
}
namespace PoisonKing
{
	public class PoisonBottlePreload : MonoBehaviour
	{
		private IEnumerator Start()
		{
			yield return PoisonResources.Load();
		}
	}
	public class PoisonBottleSwap : MonoBehaviour
	{
		public PoisonLauncher Launcher;

		private FVRFireArmRound accepted;

		private void OnTriggerEnter(Collider other)
		{
			Check(other);
		}

		private void OnTriggerStay(Collider other)
		{
			Check(other);
		}

		private void Check(Collider other)
		{
			FVRFireArmRound componentInParent = ((Component)other).GetComponentInParent<FVRFireArmRound>();
			if (!((Object)(object)componentInParent == (Object)null) && !((Object)(object)componentInParent == (Object)(object)accepted) && ((FVRInteractiveObject)componentInParent).IsHeld && Launcher.TryLoad(componentInParent))
			{
				accepted = componentInParent;
			}
		}
	}
	public class PoisonFireImpact : MonoBehaviour
	{
		private IEnumerator Start()
		{
			yield return PoisonResources.Load();
			Molotov source = PoisonResources.FireSource;
			if ((Object)(object)source == (Object)null)
			{
				Debug.LogError((object)"POISON_FIRE_SOURCE_UNAVAILABLE");
				Object.Destroy((Object)(object)((Component)this).gameObject);
				yield break;
			}
			Object.Instantiate<GameObject>(source.Prefab_FireSplosion, ((Component)this).transform.position, Quaternion.identity);
			if (source.AudEvent_Ignite != null)
			{
				SM.PlayGenericSound(source.AudEvent_Ignite, ((Component)this).transform.position);
			}
			int patches = 0;
			RaycastHit hit = default(RaycastHit);
			for (int i = 0; i < 5; i++)
			{
				if (patches >= 3)
				{
					break;
				}
				Vector3 val = ((i != 0) ? Random.onUnitSphere : Vector3.down);
				val.y = 0f - Mathf.Abs(val.y);
				if (Physics.Raycast(((Component)this).transform.position + Vector3.up, val, ref hit, source.GroundFireRange, LayerMask.op_Implicit(source.LM_Env), (QueryTriggerInteraction)1))
				{
					Object.Instantiate<GameObject>(source.Prefab_GroundFire, ((RaycastHit)(ref hit)).point, Quaternion.LookRotation(Vector3.up));
					patches++;
				}
			}
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}
	}
	[HarmonyPatch(typeof(ItemSpawnerEntry), "PopulateIDsFromObj", new Type[] { })]
	public static class PoisonIcons
	{
		private static Dictionary<string, Sprite> loaded = new Dictionary<string, Sprite>();

		[HarmonyPostfix]
		private static void Apply(ItemSpawnerEntry __instance)
		{
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			string text = ((__instance.MainObjectID == "NetherPoisonKing") ? "gun" : ((__instance.MainObjectID == "PoisonKingMagazine200") ? "magazine" : ((!(__instance.MainObjectID == "PoisonKingIncendiaryBottle")) ? null : "bottle")));
			if (text == null)
			{
				return;
			}
			if (!loaded.TryGetValue(text, out var value))
			{
				string text2 = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "icons/icon-" + text + ".png");
				if (!File.Exists(text2))
				{
					Debug.LogError((object)("POISON_ICON_MISSING " + text2));
					return;
				}
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!val.LoadImage(File.ReadAllBytes(text2), true))
				{
					Object.Destroy((Object)(object)val);
					return;
				}
				((Object)val).name = "Poison King " + text + " icon 1024";
				((Object)val).hideFlags = (HideFlags)32;
				value = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
				((Object)value).hideFlags = (HideFlags)32;
				loaded.Add(text, value);
			}
			__instance.EntryIcon = value;
		}
	}
	public class PoisonLauncher : MonoBehaviour
	{
		public const int BottleClass = 190217;

		public ClosedBoltWeapon Firearm;

		public FVRFireArmAttachmentMount Mount;

		public FVRFireArmChamber Chamber;

		public Transform Muzzle;

		public GameObject BottleArt;

		public GameObject Glow;

		public FVRFirearmAudioSet SourceAudio;

		public M203 Backend;

		public bool Ready;

		private float lastFire = -10f;

		private FVRFireArmRound loadingRound;

		private IEnumerator Start()
		{
			yield return PoisonResources.Load();
			if (!PoisonResources.Ready)
			{
				yield break;
			}
			GameObject go = Object.Instantiate<GameObject>(PoisonResources.M203Prefab);
			go.SetActive(true);
			AttachableFirearmPhysicalObject attachment = go.GetComponent<AttachableFirearmPhysicalObject>();
			((Component)attachment).transform.position = ((Component)Mount).transform.position;
			((Component)attachment).transform.rotation = ((Component)Mount).transform.rotation;
			((FVRFireArmAttachment)attachment).AttachToMount(Mount, false);
			Backend = go.GetComponent<M203>();
			((AttachableFirearm)Backend).OverrideFA = (FVRFireArm)(object)Firearm;
			((AttachableFirearm)Backend).AudioClipSet = Object.Instantiate<FVRFirearmAudioSet>(PoisonResources.GrenadeAudio);
			((AttachableFirearm)Backend).AudioClipSet.BreachOpen = SourceAudio.BreachOpen;
			((AttachableFirearm)Backend).AudioClipSet.BreachClose = SourceAudio.BreachClose;
			Backend.Chamber = Chamber;
			((AttachableFirearm)Backend).MuzzlePos = Muzzle;
			((AttachableFirearm)Backend).CurrentMuzzle = Muzzle;
			Chamber.Firearm = (FVRFireArm)(object)Firearm;
			Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				val.enabled = false;
			}
			Collider[] componentsInChildren2 = go.GetComponentsInChildren<Collider>(true);
			foreach (Collider val2 in componentsInChildren2)
			{
				val2.enabled = false;
			}
			for (int k = 0; k < 600; k++)
			{
				if (AM.STypeDic != null && AM.STypeDic.ContainsKey((FireArmRoundType)23) && AM.STypeDic[(FireArmRoundType)23].ContainsKey((FireArmRoundClass)190217))
				{
					break;
				}
				yield return null;
			}
			if (AM.STypeDic == null || !AM.STypeDic.ContainsKey((FireArmRoundType)23) || !AM.STypeDic[(FireArmRoundType)23].ContainsKey((FireArmRoundClass)190217))
			{
				Debug.LogError((object)"POISON_BOTTLE_CLASS_MISSING");
				yield break;
			}
			if (!Chamber.IsFull)
			{
				Chamber.SetRound((FireArmRoundClass)190217, ((Component)Chamber).transform.position, ((Component)Chamber).transform.rotation);
			}
			Ready = true;
			SyncVisual();
			Debug.Log((object)"POISON_LAUNCHER_READY: 200-round RPK; push-to-swap incendiary bottle");
		}

		public bool TryLoad(FVRFireArmRound incoming)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Invalid comparison between Unknown and I4
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			if (!Ready || (Object)(object)incoming == (Object)null || (Object)(object)incoming == (Object)(object)loadingRound || incoming.IsSpent || (int)incoming.RoundType != 23 || (int)incoming.RoundClass != 190217)
			{
				return false;
			}
			loadingRound = incoming;
			if (Chamber.IsFull)
			{
				if ((Object)(object)Backend != (Object)null)
				{
					((AttachableFirearm)Backend).PlayAudioEvent((FirearmAudioEventType)17, 1f);
				}
				Chamber.EjectRound(((Component)Chamber).transform.position + ((Component)this).transform.right * 0.075f, ((Component)this).transform.right * 0.7f + Vector3.down * 0.25f, Vector3.zero, false);
			}
			Chamber.SetRound(incoming, true);
			bool flag = Chamber.IsFull && !Chamber.IsSpent;
			if (flag)
			{
				ConsumeRound(incoming);
				if ((Object)(object)Backend != (Object)null)
				{
					((AttachableFirearm)Backend).PlayAudioEvent((FirearmAudioEventType)18, 1f);
				}
				SyncVisual();
			}
			if (!flag)
			{
				loadingRound = null;
			}
			return flag;
		}

		private void ConsumeRound(FVRFireArmRound incoming)
		{
			((FVRInteractiveObject)incoming).ForceBreakInteraction();
			((FVRPhysicalObject)incoming).ClearQuickbeltState();
			Object.Destroy((Object)(object)((Component)incoming).gameObject);
		}

		public bool TryFire()
		{
			if (!Ready || (Object)(object)Backend == (Object)null || !Chamber.IsFull || Chamber.IsSpent || Time.time - lastFire < 0.25f)
			{
				return false;
			}
			Backend.Chamber = Chamber;
			((AttachableFirearm)Backend).MuzzlePos = Muzzle;
			((AttachableFirearm)Backend).CurrentMuzzle = Muzzle;
			Backend.Fire(true);
			if (!Chamber.IsSpent)
			{
				return false;
			}
			lastFire = Time.time;
			SyncVisual();
			return true;
		}

		public void SyncVisual()
		{
			if ((Object)(object)BottleArt != (Object)null)
			{
				BottleArt.SetActive(Chamber.IsFull);
			}
			if ((Object)(object)Glow != (Object)null)
			{
				Glow.SetActive(Chamber.IsFull && !Chamber.IsSpent);
			}
		}

		private void LateUpdate()
		{
			SyncVisual();
		}

		private void OnDestroy()
		{
			if ((Object)(object)Backend != (Object)null)
			{
				if ((Object)(object)((AttachableFirearm)Backend).AudioClipSet != (Object)null && (Object)(object)((AttachableFirearm)Backend).AudioClipSet != (Object)(object)PoisonResources.GrenadeAudio)
				{
					Object.Destroy((Object)(object)((AttachableFirearm)Backend).AudioClipSet);
				}
				Object.Destroy((Object)(object)((Component)Backend).gameObject);
			}
		}
	}
	public class PoisonLauncherGrip : FVRAlternateGrip
	{
		public PoisonLauncher Launcher;

		private bool armed;

		public override void BeginInteraction(FVRViveHand hand)
		{
			((FVRAlternateGrip)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)
		{
			((FVRAlternateGrip)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;
			((FVRAlternateGrip)this).EndInteraction(hand);
		}
	}
	public class PoisonMagazine : 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 static class PoisonResources
	{
		public static GameObject M203Prefab;

		public static Molotov FireSource;

		public static FVRFirearmAudioSet GrenadeAudio;

		private static bool loading;

		public static bool Ready => (Object)(object)M203Prefab != (Object)null && (Object)(object)FireSource != (Object)null && (Object)(object)GrenadeAudio != (Object)null;

		public static IEnumerator Load()
		{
			if (Ready)
			{
				yield break;
			}
			if (loading)
			{
				for (int i = 0; i < 900; i++)
				{
					if (!loading)
					{
						break;
					}
					yield return null;
				}
				yield break;
			}
			loading = true;
			try
			{
				FVRObject a = null;
				FVRObject b = null;
				FVRObject c = null;
				for (int j = 0; j < 900; j++)
				{
					if (IM.OD != null && IM.OD.TryGetValue("M203Picatinny", out a) && IM.OD.TryGetValue("Molotov", out b) && IM.OD.TryGetValue("MGLGrenadeLauncher", out c))
					{
						break;
					}
					yield return null;
				}
				if ((Object)(object)a == (Object)null || (Object)(object)b == (Object)null || (Object)(object)c == (Object)null)
				{
					Debug.LogError((object)"POISON_NATIVE_RESOURCES_MISSING");
					yield break;
				}
				AnvilCallback<GameObject> ar = ((AnvilAsset)a).GetGameObjectAsync();
				yield return ar;
				AnvilCallback<GameObject> br = ((AnvilAsset)b).GetGameObjectAsync();
				yield return br;
				AnvilCallback<GameObject> cr = ((AnvilAsset)c).GetGameObjectAsync();
				yield return cr;
				if (!((Object)(object)ar.Result == (Object)null) && !((Object)(object)br.Result == (Object)null) && !((Object)(object)cr.Result == (Object)null))
				{
					M203Prefab = ar.Result;
					FireSource = br.Result.GetComponent<Molotov>();
					GrenadeAudio = cr.Result.GetComponent<FVRFireArm>().AudioClipSet;
					Debug.Log((object)"POISON_NATIVE_RESOURCES_READY");
				}
			}
			finally
			{
				loading = false;
			}
		}
	}
}