Decompiled source of PocketBugle v1.0.4

plugins/com.github.mondash.PocketBugle.dll

Decompiled 2 weeks 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.Configuration;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.mondash.PocketBugle")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4+8e8ead4d41b4d91758a4f4245f6d41b2b72176d7")]
[assembly: AssemblyProduct("com.github.mondash.PocketBugle")]
[assembly: AssemblyTitle("PocketBugle")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace PocketBugle
{
	[BepInPlugin("com.github.mondash.PocketBugle", "PocketBugle", "1.0.4")]
	public class Plugin : BaseUnityPlugin
	{
		private const ushort BugleItemID = 15;

		private const string BugleItemName = "Bugle";

		private const string DestroyHeldItemMethod = "DestroyHeldItemRpc";

		private const string SpawnItemInHandMethod = "RPC_SpawnItemInHandMaster";

		public const string Id = "com.github.mondash.PocketBugle";

		private static KeyCode PocketKey => PocketConfig.PocketKey.Value;

		public static string Name => "PocketBugle";

		public static string Version => "1.0.4";

		private void Awake()
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin waking...");
			PocketConfig.Bind(((BaseUnityPlugin)this).Config);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin awake!");
		}

		private static bool IsBugle(Item? item)
		{
			if (Object.op_Implicit((Object)(object)item))
			{
				return item.itemID == 15;
			}
			return false;
		}

		private static bool IsHoldingBugle(Character character)
		{
			return IsBugle(character.data.currentItem);
		}

		private static void DestroyHeldItem(Character character)
		{
			character.refs.items.photonView.RPC("DestroyHeldItemRpc", PhotonNetwork.LocalPlayer, Array.Empty<object>());
		}

		private static bool TryDestroyHeldBugle(Character character)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			if (!IsHoldingBugle(character))
			{
				return false;
			}
			DestroyHeldItem(character);
			Optionable<byte> currentSelectedSlot = character.refs.items.currentSelectedSlot;
			if (currentSelectedSlot.IsSome)
			{
				character.player.EmptySlot(currentSelectedSlot);
			}
			return true;
		}

		private static bool TryEquipBugle(Character character)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (IsHoldingBugle(character))
			{
				return true;
			}
			if (!character.player.tempFullSlot.IsEmpty())
			{
				return true;
			}
			ItemSlot[] array = character.player.itemSlots ?? Array.Empty<ItemSlot>();
			for (byte b = 0; b < array.Length; b++)
			{
				Item item = array[b]?.prefab;
				if (IsBugle(item))
				{
					character.refs.items.EquipSlot(Optionable<byte>.Some(b));
					return true;
				}
			}
			return false;
		}

		private static void SpawnBugle(Character character)
		{
			character.refs.items.photonView.RPC("RPC_SpawnItemInHandMaster", (RpcTarget)2, new object[1] { "Bugle" });
		}

		private void Update()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (Input.GetKeyDown(PocketKey))
			{
				Character localCharacter = Character.localCharacter;
				if (Object.op_Implicit((Object)(object)localCharacter) && !TryDestroyHeldBugle(localCharacter) && !TryEquipBugle(localCharacter))
				{
					SpawnBugle(localCharacter);
				}
			}
		}
	}
	internal static class PocketConfig
	{
		public static ConfigEntry<KeyCode> PocketKey;

		public static void Bind(ConfigFile config)
		{
			PocketKey = config.Bind<KeyCode>("Control", "PocketKey", (KeyCode)98, "Keyboard key used to spawn or destroy held bugle");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}