Decompiled source of BoarderArmorStandStats v1.0.0

BoarderArmorStandStats.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BoarderArmorStandStats")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Azumatt")]
[assembly: AssemblyProduct("BoarderArmorStandStats")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace BoarderArmorStandStats
{
	[BepInPlugin("Azumatt.BoarderArmorStandStats", "BoarderArmorStandStats", "1.0.0")]
	public class BoarderArmorStandStatsPlugin : BaseUnityPlugin
	{
		private class AcceptableShortcuts : AcceptableValueBase
		{
			public AcceptableShortcuts()
				: base(typeof(KeyboardShortcut))
			{
			}

			public override object Clamp(object value)
			{
				return value;
			}

			public override bool IsValid(object value)
			{
				return true;
			}

			public override string ToDescriptionString()
			{
				return "# Acceptable values: " + string.Join(", ", KeyboardShortcut.AllKeyCodes);
			}
		}

		internal const string ModName = "BoarderArmorStandStats";

		internal const string ModVersion = "1.0.0";

		internal const string Author = "Azumatt";

		private const string ModGUID = "Azumatt.BoarderArmorStandStats";

		private static string ConfigFileName = "Azumatt.BoarderArmorStandStats.cfg";

		private static string ConfigFileFullPath;

		private readonly Harmony _harmony = new Harmony("Azumatt.BoarderArmorStandStats");

		public static readonly ManualLogSource BoarderArmorStandStatsPluginLogger;

		public static ConfigEntry<KeyboardShortcut> cyclekeyLeft;

		public static ConfigEntry<KeyboardShortcut> cyclekeyRight;

		public void Awake()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			cyclekeyLeft = config<KeyboardShortcut>("1 - General", "Cycle Key Left", new KeyboardShortcut((KeyCode)276, Array.Empty<KeyCode>()), "Key to cycle left when looking at the armour stand.");
			cyclekeyRight = config<KeyboardShortcut>("1 - General", "Cycle Key Right", new KeyboardShortcut((KeyCode)275, Array.Empty<KeyCode>()), "Key to cycle right when looking at the armour stand.");
			_harmony.PatchAll(Assembly.GetExecutingAssembly());
		}

		private void OnDestroy()
		{
			((BaseUnityPlugin)this).Config.Save();
		}

		private void SetupWatcher()
		{
			FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
			fileSystemWatcher.Changed += ReadConfigValues;
			fileSystemWatcher.Created += ReadConfigValues;
			fileSystemWatcher.Renamed += ReadConfigValues;
			fileSystemWatcher.IncludeSubdirectories = true;
			fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
			fileSystemWatcher.EnableRaisingEvents = true;
		}

		private void ReadConfigValues(object sender, FileSystemEventArgs e)
		{
			if (!File.Exists(ConfigFileFullPath))
			{
				return;
			}
			try
			{
				((BaseUnityPlugin)this).Logger.LogDebug((object)"ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("There was an issue loading your " + ConfigFileName));
				((BaseUnityPlugin)this).Logger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		private ConfigEntry<T> config<T>(string group, string name, T value, ConfigDescription description)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			ConfigDescription val = new ConfigDescription(description.Description + " [Not Synced with Server]", description.AcceptableValues, description.Tags);
			return ((BaseUnityPlugin)this).Config.Bind<T>(group, name, value, val);
		}

		private ConfigEntry<T> config<T>(string group, string name, T value, string description)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			return config(group, name, value, new ConfigDescription(description, (AcceptableValueBase)null, Array.Empty<object>()));
		}

		static BoarderArmorStandStatsPlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			BoarderArmorStandStatsPluginLogger = Logger.CreateLogSource("BoarderArmorStandStats");
			cyclekeyLeft = null;
			cyclekeyRight = null;
		}
	}
	public static class KeyboardExtensions
	{
		public static bool IsKeyDown(this KeyboardShortcut shortcut)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKeyDown(((KeyboardShortcut)(ref shortcut)).MainKey))
			{
				return ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey);
			}
			return false;
		}

		public static bool IsKeyHeld(this KeyboardShortcut shortcut)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			if ((int)((KeyboardShortcut)(ref shortcut)).MainKey != 0 && Input.GetKey(((KeyboardShortcut)(ref shortcut)).MainKey))
			{
				return ((KeyboardShortcut)(ref shortcut)).Modifiers.All((Func<KeyCode, bool>)Input.GetKey);
			}
			return false;
		}
	}
	public class ArmorStandExtension : MonoBehaviour
	{
		public int currentSlotIndex;
	}
	[HarmonyPatch(typeof(ArmorStand), "Awake")]
	public static class ArmorStand_Awake_Patch
	{
		private static void Postfix(ArmorStand __instance)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			ArmorStand __instance2 = __instance;
			ArmorStandExtension extension = ((Component)__instance2).gameObject.AddComponent<ArmorStandExtension>();
			foreach (ArmorStandSlot slot in __instance2.m_slots)
			{
				if (!((Object)(object)slot.m_switch != (Object)null))
				{
					continue;
				}
				slot.m_switch.m_onHover = (TooltipCallback)delegate
				{
					//IL_0010: Unknown result type (might be due to invalid IL or missing references)
					//IL_004d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0094: Unknown result type (might be due to invalid IL or missing references)
					if (!PrivateArea.CheckAccess(((Component)__instance2).transform.position, 0f, false, false))
					{
						return Localization.instance.Localize(__instance2.m_name + "\n$piece_noaccess");
					}
					if (BoarderArmorStandStatsPlugin.cyclekeyLeft.Value.IsKeyDown())
					{
						extension.currentSlotIndex = GetNextNonEmptySlotIndex(__instance2, extension.currentSlotIndex, -1);
					}
					else if (BoarderArmorStandStatsPlugin.cyclekeyRight.Value.IsKeyDown())
					{
						extension.currentSlotIndex = GetNextNonEmptySlotIndex(__instance2, extension.currentSlotIndex, 1);
					}
					else if (string.IsNullOrEmpty(__instance2.m_slots[extension.currentSlotIndex].m_visualName))
					{
						extension.currentSlotIndex = GetNextNonEmptySlotIndex(__instance2, extension.currentSlotIndex, 1);
					}
					string text = Localization.instance.Localize(slot.m_switch.m_hoverText + "\n[<color=yellow><b>1-8</b></color>] $piece_itemstand_attach" + ((__instance2.GetNrOfAttachedItems() > 0) ? "\n[<color=yellow><b>$KEY_Use</b></color>] $piece_itemstand_take" : ""));
					text = text + Environment.NewLine + "[<color=yellow>Left/Right Arrow</color>] Cycle Slots" + Environment.NewLine;
					ArmorStandSlot val = __instance2.m_slots[extension.currentSlotIndex];
					if (string.IsNullOrEmpty(val.m_visualName))
					{
						return Localization.instance.Localize(text);
					}
					string itemStatsFromZDO = GetItemStatsFromZDO(__instance2, extension.currentSlotIndex, val.m_visualName);
					text = text + Environment.NewLine + itemStatsFromZDO;
					return Localization.instance.Localize(text);
				};
			}
		}

		private static int GetNextNonEmptySlotIndex(ArmorStand armorStand, int currentIndex, int direction)
		{
			int count = armorStand.m_slots.Count;
			int num = currentIndex;
			for (int i = 0; i < count; i++)
			{
				num = (num + direction + count) % count;
				if (!string.IsNullOrEmpty(armorStand.m_slots[num].m_visualName))
				{
					return num;
				}
			}
			return currentIndex;
		}

		private static string GetItemStatsFromZDO(ArmorStand armorStand, int index, string itemName)
		{
			GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(armorStand.m_nview.GetZDO().GetString(index + "_item", ""));
			if ((Object)(object)itemPrefab == (Object)null)
			{
				return "";
			}
			itemPrefab = Object.Instantiate<GameObject>(itemPrefab);
			ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
			if ((Object)(object)component == (Object)null)
			{
				return "";
			}
			ItemData val = component.m_itemData.Clone();
			ItemDrop.LoadFromZDO(index, val, armorStand.m_nview.GetZDO());
			try
			{
				ZNetScene.instance.Destroy(itemPrefab);
			}
			catch
			{
				Object.DestroyImmediate((Object)(object)itemPrefab);
			}
			return Localization.instance.Localize(val.m_shared.m_name) + Environment.NewLine + val.GetTooltip(-1);
		}
	}
}