Decompiled source of CloakBeGone v1.0.1

CloakBeGone.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("CloakBeGone")]
[assembly: AssemblyDescription("https://valheim.thunderstore.io/package/blacks7ar/CloakBeGone/")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("blacks7ar")]
[assembly: AssemblyProduct("CloakBeGone")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("F21E0AD8-5455-4240-8759-8638AF187238")]
[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 CloakBeGone;

[BepInPlugin("blacks7ar.CloakBeGone", "CloakBeGone", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(VisEquipment), "SetShoulderEquipped")]
	public static class Patches
	{
		public static bool Prefix(ref VisEquipment __instance, int hash, int variant)
		{
			//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_00ba: 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) && _capeOn && ((Character)Player.m_localPlayer).TakeInput())
			{
				if (__instance.m_shoulderItemInstances == null)
				{
					return false;
				}
				foreach (GameObject shoulderItemInstance in __instance.m_shoulderItemInstances)
				{
					if (Object.op_Implicit((Object)(object)__instance.m_lodGroup))
					{
						Utils.RemoveFromLodgroup(__instance.m_lodGroup, shoulderItemInstance);
					}
					Object.Destroy((Object)(object)shoulderItemInstance);
				}
				_capeOn = false;
				return false;
			}
			if (Input.GetKeyDown(_Hotkey.Value) && !_capeOn && ((Character)Player.m_localPlayer).TakeInput())
			{
				__instance.m_shoulderItemInstances = __instance.AttachArmor(hash, variant);
				_capeOn = true;
				return false;
			}
			return true;
		}
	}

	private const string modGUID = "blacks7ar.CloakBeGone";

	public const string modName = "CloakBeGone";

	public const string modAuthor = "blacks7ar";

	public const string modVersion = "1.0.1";

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

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

	private static ConfigEntry<KeyCode> _Hotkey;

	private static bool _capeOn = 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 cloak.");
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		_harmony.PatchAll(executingAssembly);
	}
}