Decompiled source of NoUtilityBelt v0.1.0

NoUtilityBelt.dll

Decompiled 3 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NoUtilityBelt.Config;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;

[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("NoUtilityBelt")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Removes the vanilla Tab utility-belt slot so it stops conflicting with ReservedItemSlotCore (FlipMods) reserved slots. Tools grab into normal slots, Tab is inert, belt HUD hidden. ReservedItemSlotCore not required. Client-side.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+16c075f6f4cfce48c86c16a0d303d7979c7c76f1")]
[assembly: AssemblyProduct("NoUtilityBelt")]
[assembly: AssemblyTitle("NoUtilityBelt")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 NoUtilityBelt
{
	[BepInPlugin("Haaylo.NoUtilityBelt", "NoUtilityBelt", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		public static Plugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				ModConfig.Bind(((BaseUnityPlugin)this).Config);
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Config binding failed; using defaults where possible: {arg}");
			}
			try
			{
				_harmony = new Harmony("Haaylo.NoUtilityBelt");
				_harmony.PatchAll(typeof(Plugin).Assembly);
				int num = 0;
				foreach (MethodBase patchedMethod in _harmony.GetPatchedMethods())
				{
					_ = patchedMethod;
					num++;
				}
				Log.LogInfo((object)string.Format("{0} {1}: {2} game methods patched.", "NoUtilityBelt", "0.1.0", num));
			}
			catch (Exception arg2)
			{
				Log.LogError((object)$"Harmony patching failed; the mod will stay idle: {arg2}");
			}
		}
	}
	public static class PluginInfo
	{
		public const string GUID = "Haaylo.NoUtilityBelt";

		public const string NAME = "NoUtilityBelt";

		public const string VERSION = "0.1.0";
	}
}
namespace NoUtilityBelt.Modules.Belt
{
	internal static class BeltPatchState
	{
		private static bool _faulted;

		public static bool Active
		{
			get
			{
				if (!_faulted)
				{
					return ModConfig.Enabled.Value;
				}
				return false;
			}
		}

		public static void Fault(Exception e)
		{
			if (!_faulted)
			{
				_faulted = true;
				Plugin.Log.LogError((object)$"Utility belt patch failed; vanilla belt restored for this session: {e}");
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "FirstEmptyItemSlot")]
	internal static class PlayerControllerB_FirstEmptyItemSlot_Patch
	{
		private static void Prefix(ref GrabbableObject attemptingGrab)
		{
			try
			{
				if (BeltPatchState.Active)
				{
					attemptingGrab = null;
				}
			}
			catch (Exception e)
			{
				BeltPatchState.Fault(e);
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "UseUtilitySlot_performed")]
	internal static class PlayerControllerB_UseUtilitySlot_Patch
	{
		private static bool Prefix(PlayerControllerB __instance, CallbackContext context)
		{
			try
			{
				if (!BeltPatchState.Active)
				{
					return true;
				}
				return (Object)(object)__instance.ItemOnlySlot != (Object)null;
			}
			catch (Exception e)
			{
				BeltPatchState.Fault(e);
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(HUDManager), "SetUtilitySlotKeyText")]
	internal static class HUDManager_SetUtilitySlotKeyText_Patch
	{
		private static void Postfix(HUDManager __instance)
		{
			try
			{
				if (BeltPatchState.Active)
				{
					if ((Object)(object)__instance.utilitySlotKeyText != (Object)null)
					{
						((TMP_Text)__instance.utilitySlotKeyText).text = "";
					}
					if ((Object)(object)__instance.itemOnlySlotIconFrame != (Object)null)
					{
						((Component)__instance.itemOnlySlotIconFrame).gameObject.SetActive(false);
					}
					if ((Object)(object)__instance.itemOnlySlotIcon != (Object)null)
					{
						((Component)__instance.itemOnlySlotIcon).gameObject.SetActive(false);
					}
				}
			}
			catch (Exception e)
			{
				BeltPatchState.Fault(e);
			}
		}
	}
}
namespace NoUtilityBelt.Config
{
	public static class ModConfig
	{
		public static ConfigEntry<bool> Enabled;

		public static void Bind(ConfigFile config)
		{
			Enabled = config.Bind<bool>("General", "Enabled", true, "Remove the Tab utility-belt slot: tools grab into your normal four slots, Tab does nothing, and the belt HUD is hidden. Client-side; takes effect on the next HUD load.");
		}
	}
}