Decompiled source of BombVest v1.0.1

BombVest.dll

Decompiled 3 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using ItemAPI;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BombVest")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BombVest")]
[assembly: AssemblyTitle("BombVest")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BombVest
{
	[BepInPlugin("BombVest", "BombVest", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public class BombVest : Equipment
		{
			public override string Name => "Bomb Vest";

			public override string Description
			{
				get
				{
					//IL_000a: Unknown result type (might be due to invalid IL or missing references)
					//IL_000f: 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)
					KeyboardShortcut value = ExplodeHotkey.Value;
					return $"VERY DEADLY! (Can be exploded by pressing {((KeyboardShortcut)(ref value)).MainKey})";
				}
			}

			public override EquipmentType ItemType => (EquipmentType)2;

			public override int? maxDurability => 1;

			public override Sprite Icon => ItemAPI.LoadSpriteFromEmbedded("BombVest.BombVest.png");

			public override GameObject Prefab => ItemAPI.LoadGameObject("BombVest.bombvest.bundle", "BombVest.prefab");

			public override Vector3? DroppedSize => new Vector3(0.5f, 0.5f, 0.5f);

			public override void OnBreak(PlayerNetworking player)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: 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)
				Vector3 position = ((GameEntityBase)player).Position;
				NetworkSpawner.RequestSpawn("Grenade", position, "BombVest");
			}

			public override void OnEquip(GameObject visualObject, PlayerNetworking player)
			{
				//IL_0041: 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_0081: Unknown result type (might be due to invalid IL or missing references)
				Transform val = ItemAPI.FindChildRecursive(((Component)player).transform, "spine_02");
				if ((Object)(object)val != (Object)null)
				{
					visualObject.transform.SetParent(val, false);
					visualObject.transform.localPosition = new Vector3(0f, -0.3f, -0.15f);
					visualObject.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
					visualObject.transform.localScale = new Vector3(1f, 1f, 1f);
				}
				else
				{
					Logger.LogError((object)"Could not find chest bone anywhere in the player hierarchy.");
				}
			}
		}

		public class BombVestRecipe : CraftingRecipe
		{
			public override Equipment Equipment => (Equipment)(object)new BombVest();

			public override CraftingCost[] CostTable => (CraftingCost[])(object)new CraftingCost[3]
			{
				CraftingCost.op_Implicit((ItemAPI.GetItemData("Gnomium"), 1)),
				CraftingCost.op_Implicit(((ResourceTypes)1, 2)),
				CraftingCost.op_Implicit(((ResourceTypes)4, 2))
			};
		}

		internal static ManualLogSource Logger;

		private static readonly MethodInfo GrenadeExplodeMethod = typeof(Grenade).GetMethod("InstantExplodeRpc", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		public static ConfigEntry<KeyboardShortcut> ExplodeHotkey { get; set; }

		private void Awake()
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin BombVest is loaded!");
			if (!Chainloader.PluginInfos.ContainsKey("com.mattcy.itemapi"))
			{
				Logger.LogError((object)"Failed To Load BombVest, ItemAPI is not Present!");
				return;
			}
			ItemAPI.Init(Logger);
			ItemAPI.onItemSpawnedViaRequest = (Action<GameObject, string>)Delegate.Combine(ItemAPI.onItemSpawnedViaRequest, (Action<GameObject, string>)delegate(GameObject spawnedObject, string? uniqueId)
			{
				ExplodeGrenade(spawnedObject, uniqueId);
			});
			Harmony val = new Harmony("BombVest");
			val.PatchAll();
			ExplodeHotkey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Config", "Explode Bombvest", new KeyboardShortcut((KeyCode)120, Array.Empty<KeyCode>()), (ConfigDescription)null);
		}

		private void ExplodeGrenade(GameObject gameObject, string uniqueId)
		{
			if (uniqueId == "BombVest")
			{
				Grenade component = gameObject.GetComponent<Grenade>();
				if ((Object)(object)component != (Object)null && GrenadeExplodeMethod != null)
				{
					GrenadeExplodeMethod.Invoke(component, null);
				}
			}
		}

		public static bool IsLobbyOrTransitionState()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Invalid comparison between Unknown and I4
			GameProgressionManager val = Object.FindObjectOfType<GameProgressionManager>();
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			try
			{
				return (int)val.CurrentGameState == 0;
			}
			catch
			{
				return false;
			}
		}

		private void Update()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			PlayerNetworking localPlayer = ItemAPI.GetLocalPlayer();
			if ((Object)(object)localPlayer != (Object)null && !IsLobbyOrTransitionState())
			{
				KeyboardShortcut value = ExplodeHotkey.Value;
				if (Input.GetKeyDown(((KeyboardShortcut)(ref value)).MainKey))
				{
					ItemAPI.ConsumeItemDurability(ItemAPI.GetItemIndex("Bomb Vest"), 1);
				}
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BombVest";

		public const string PLUGIN_NAME = "BombVest";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}