Decompiled source of HelmetBeGone v1.0.8

HelmetBeGone.dll

Decompiled 5 days 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 HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("blacks7ar")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.8")]
[assembly: AssemblyInformationalVersion("1.0.8")]
[assembly: AssemblyProduct("HelmetBeGone")]
[assembly: AssemblyTitle("HelmetBeGone")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.8.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace HelmetBeGone
{
	[BepInPlugin("blacks7ar.HelmetBeGone", "HelmetBeGone", "1.0.8")]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch]
		public static class VisEquipmentPatch
		{
			[HarmonyPrefix]
			[HarmonyPatch(typeof(VisEquipment), "SetHelmetEquipped")]
			private static bool SetHelmetEquipped_Prefix(ref VisEquipment __instance, int hash)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0084: Unknown result type (might be due to invalid IL or missing references)
				//IL_0122: Unknown result type (might be due to invalid IL or missing references)
				//IL_011a: Unknown result type (might be due to invalid IL or missing references)
				switch (hash)
				{
				case 0:
					return true;
				case 703889544:
					return true;
				default:
				{
					Scene activeScene = SceneManager.GetActiveScene();
					if (((Scene)(ref activeScene)).name != "main")
					{
						return false;
					}
					if (_hideShowHelmet == null)
					{
						return false;
					}
					if (Input.GetKeyDown(_hideShowHelmet.Value) && !_helmetOn && ((Character)Player.m_localPlayer).TakeInput())
					{
						if (Object.op_Implicit((Object)(object)__instance.m_helmetItemInstance) && (Object)(object)__instance.m_helmetItemInstance != (Object)null)
						{
							__instance.m_helmetHideHair = (HelmetHairType)2;
							__instance.m_helmetHideBeard = (HelmetHairType)0;
							bool flag = false;
							if (Object.op_Implicit((Object)(object)__instance.m_nViewOverride))
							{
								flag = ((Object)__instance.m_nViewOverride).name.ToLower().Contains("stand");
							}
							if (!flag)
							{
								__instance.m_helmetItemInstance.SetActive(false);
							}
						}
						_helmetOn = true;
						return true;
					}
					if (Input.GetKeyDown(_hideShowHelmet.Value) && _helmetOn && ((Character)Player.m_localPlayer).TakeInput())
					{
						if (Object.op_Implicit((Object)(object)__instance.m_hairItemInstance))
						{
							if (!__instance.m_helmetItem.ToLower().Contains("dverger"))
							{
								__instance.m_helmetHideHair = (HelmetHairType)1;
							}
							__instance.m_helmetHideBeard = (HelmetHairType)0;
							__instance.m_helmetItemInstance.SetActive(true);
						}
						_helmetOn = false;
						return false;
					}
					return false;
				}
				}
			}
		}

		private const string modGUID = "blacks7ar.HelmetBeGone";

		public const string modName = "HelmetBeGone";

		public const string modAuthor = "blacks7ar";

		public const string modVersion = "1.0.8";

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

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

		private static ConfigEntry<KeyCode> _hideShowHelmet;

		private static bool _helmetOn;

		public void Awake()
		{
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
			_hideShowHelmet = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "Hotkey", (KeyCode)104, "Hotkey to hide/show helmet.");
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.PatchAll(executingAssembly);
		}
	}
}