Decompiled source of ArmorBeGone v1.0.1

ArmorBeGone.dll

Decompiled 6 months ago
using System.Diagnostics;
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 HarmonyLib;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ArmorBeGone")]
[assembly: AssemblyDescription("https://valheim.thunderstore.io/package/blacks7ar/ArmorBeGone/")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("blacks7ar")]
[assembly: AssemblyProduct("ArmorBeGone")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("57719271-F186-4AE6-ADF5-7AB65B20268F")]
[assembly: AssemblyFileVersion("1.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace ArmorBeGone;

[BepInPlugin("blacks7ar.ArmorBeGone", "ArmorBeGone", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(VisEquipment), "SetChestEquipped")]
	public static class Patches
	{
		public static bool Prefix(ref VisEquipment __instance, int hash)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			if (hash == 0)
			{
				return true;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "main" || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return false;
			}
			if (Input.GetKeyDown(_Hotkey.Value) && !_armorOn && ((Character)Player.m_localPlayer).TakeInput())
			{
				GameObject itemPrefab = ObjectDB.instance.GetItemPrefab(hash);
				if ((Object)(object)itemPrefab == (Object)null)
				{
					ZLog.Log((object)("Missing chest item " + hash));
					return true;
				}
				ItemDrop component = itemPrefab.GetComponent<ItemDrop>();
				if (Object.op_Implicit((Object)(object)component.m_itemData.m_shared.m_armorMaterial))
				{
					((Renderer)__instance.m_bodyModel).material.SetTexture("_ChestTex", component.m_itemData.m_shared.m_armorMaterial.GetTexture("_ChestTex"));
					((Renderer)__instance.m_bodyModel).material.SetTexture("_ChestBumpMap", component.m_itemData.m_shared.m_armorMaterial.GetTexture("_ChestBumpMap"));
					((Renderer)__instance.m_bodyModel).material.SetTexture("_ChestMetal", component.m_itemData.m_shared.m_armorMaterial.GetTexture("_ChestMetal"));
				}
				__instance.m_chestItemInstances = __instance.AttachArmor(hash, -1);
				_armorOn = true;
				return true;
			}
			if (Input.GetKeyDown(_Hotkey.Value) && _armorOn && ((Character)Player.m_localPlayer).TakeInput())
			{
				if (__instance.m_chestItemInstances == null)
				{
					return false;
				}
				foreach (GameObject chestItemInstance in __instance.m_chestItemInstances)
				{
					if (Object.op_Implicit((Object)(object)__instance.m_lodGroup))
					{
						Utils.RemoveFromLodgroup(__instance.m_lodGroup, chestItemInstance);
					}
					Object.Destroy((Object)(object)chestItemInstance);
				}
				((Renderer)__instance.m_bodyModel).material.SetTexture("_ChestTex", __instance.m_emptyBodyTexture);
				((Renderer)__instance.m_bodyModel).material.SetTexture("_ChestBumpMap", (Texture)null);
				((Renderer)__instance.m_bodyModel).material.SetTexture("_ChestMetal", (Texture)null);
				_armorOn = false;
				return false;
			}
			return true;
		}
	}

	private const string modGUID = "blacks7ar.ArmorBeGone";

	public const string modName = "ArmorBeGone";

	public const string modAuthor = "blacks7ar";

	public const string modVersion = "1.0.1";

	public const string modLink = "https://valheim.thunderstore.io/package/blacks7ar/ArmorBeGone/";

	private static readonly Harmony _harmony = new Harmony("blacks7ar.ArmorBeGone");

	private static ConfigEntry<KeyCode> _Hotkey;

	private static bool _armorOn = true;

	public void Awake()
	{
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		_Hotkey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "Hotkey", (KeyCode)104, "Hotkey to press to hide the chest armor.");
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		_harmony.PatchAll(executingAssembly);
	}
}