Decompiled source of MasksDropShells v1.0.1

MasksDropShells.dll

Decompiled 9 months ago
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MasksDropShells.Patches;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("MasksDropShells")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MasksDropShells")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("37004345-adbf-41f6-9764-7b6cdecd9ae4")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MasksDropShells
{
	[BepInPlugin("Waffle.MasksDropShells", "Masks Drop Shells", "1.0.1")]
	public class MaskDropShell : BaseUnityPlugin
	{
		private const string modGUID = "Waffle.MasksDropShells";

		private const string modName = "Masks Drop Shells";

		private const string modVersion = "1.0.1";

		private readonly Harmony harmony = new Harmony("Waffle.MasksDropShells");

		public static MaskDropShell Instance;

		internal ManualLogSource mls;

		internal ConfigEntry<int> ShellChance;

		internal ConfigEntry<int> ShellRolls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Waffle.MasksDropShells");
			mls.LogInfo((object)"Masks drop shells has loaded");
			ShellChance = ((BaseUnityPlugin)this).Config.Bind<int>("General", "ShellChance", 25, "This value controls the chance of dropping a shell for each roll, as a percentage (0-100)");
			ShellRolls = ((BaseUnityPlugin)this).Config.Bind<int>("General", "ShellRolls", 2, "This value controls the ammount of times it will attempt to spawn a shotgun shell, as well as the max ammount that can be spawned");
			harmony.PatchAll(typeof(MaskDropShell));
			harmony.PatchAll(typeof(MaskedPlayerEnemy_Patches));
		}
	}
}
namespace MasksDropShells.Patches
{
	[HarmonyPatch(typeof(MaskedPlayerEnemy))]
	internal class MaskedPlayerEnemy_Patches
	{
		private static Item _shellItem;

		[HarmonyPatch("KillEnemy")]
		[HarmonyPostfix]
		internal static void DropMaskOnDeath(MaskedPlayerEnemy __instance)
		{
			//IL_00aa: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			MaskDropShell.Instance.mls.LogInfo((object)"HarmonyPatchOpened");
			if (!NetworkManager.Singleton.IsServer)
			{
				return;
			}
			Item shellItem = GetShellItem();
			int value = MaskDropShell.Instance.ShellRolls.Value;
			int value2 = MaskDropShell.Instance.ShellChance.Value;
			MaskDropShell.Instance.mls.LogInfo((object)"masked dead");
			for (int i = 0; i < value; i++)
			{
				MaskDropShell.Instance.mls.LogInfo((object)"rolling");
				int num = Random.Range(0, 100);
				MaskDropShell.Instance.mls.LogInfo((object)num);
				if (num < value2)
				{
					GameObject val = Object.Instantiate<GameObject>(shellItem.spawnPrefab, ((Component)__instance).transform.position + new Vector3(0f, 2.5f, 0f), Quaternion.identity);
					val.GetComponentInChildren<GrabbableObject>().fallTime = 0f;
					val.GetComponentInChildren<GrabbableObject>().SetScrapValue(0);
					val.GetComponentInChildren<NetworkObject>().Spawn(false);
					RoundManager.Instance.SyncScrapValuesClientRpc((NetworkObjectReference[])(object)new NetworkObjectReference[1] { NetworkObjectReference.op_Implicit(val.GetComponent<NetworkObject>()) }, new int[1] { val.GetComponent<GrabbableObject>().scrapValue });
				}
			}
		}

		private static Item GetShellItem()
		{
			if ((Object)(object)_shellItem == (Object)null)
			{
				_shellItem = StartOfRound.Instance.allItemsList.itemsList.First((Item i) => ((Object)i).name == "GunAmmo");
			}
			return _shellItem;
		}
	}
}