Decompiled source of PocketBinos v1.0.0

com.chouja.PocketBinos.dll

Decompiled 2 months 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.chouja.PocketBinos")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+8e8ead4d41b4d91758a4f4245f6d41b2b72176d7")]
[assembly: AssemblyProduct("com.chouja.PocketBinos")]
[assembly: AssemblyTitle("PocketBinos")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 PocketBinos
{
	[BepInPlugin("com.chouja.PocketBinos", "PocketBinos", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const ushort BinocularsItemID = 14;

		private const string BinocularsItemName = "Binoculars";

		private const string DestroyHeldItemMethod = "DestroyHeldItemRpc";

		private const string SpawnItemInHandMethod = "RPC_SpawnItemInHandMaster";

		public const string Id = "com.chouja.PocketBinos";

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

		public static string Name => "PocketBinos";

		public static string Version => "1.0.0";

		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 IsBinoculars(Item? item)
		{
			if (Object.op_Implicit((Object)(object)item))
			{
				return item.itemID == 14;
			}
			return false;
		}

		private static bool IsHoldingBinoculars(Character character)
		{
			return IsBinoculars(character.data.currentItem);
		}

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

		private static bool TryDestroyHeldBinoculars(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 (!IsHoldingBinoculars(character))
			{
				return false;
			}
			DestroyHeldItem(character);
			Optionable<byte> currentSelectedSlot = character.refs.items.currentSelectedSlot;
			if (currentSelectedSlot.IsSome)
			{
				character.player.EmptySlot(currentSelectedSlot);
			}
			return true;
		}

		private static bool TryEquipBinoculars(Character character)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			if (IsHoldingBinoculars(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 (IsBinoculars(item))
				{
					character.refs.items.EquipSlot(Optionable<byte>.Some(b));
					return true;
				}
			}
			return false;
		}

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

		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) && !TryDestroyHeldBinoculars(localCharacter) && !TryEquipBinoculars(localCharacter))
				{
					SpawnBinoculars(localCharacter);
				}
			}
		}
	}
	internal static class PocketConfig
	{
		public static ConfigEntry<KeyCode> PocketKey;

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