Decompiled source of AutoEquipShield v1.0.0

AutoEquipShield.dll

Decompiled 2 weeks ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("AutoEquipShield")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoEquipShield")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3ed74652-e10c-4406-9dcc-d66c0e28f5d7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace AutoEquipShield;

[BepInPlugin("com.yourname.autoequipshield", "Auto Equip Shield", "1.0.0")]
public class AutoEquipShieldPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Humanoid), "EquipItem")]
	public static class EquipItem_Patch
	{
		private static readonly FieldRef<Humanoid, ItemData> leftItemRef = AccessTools.FieldRefAccess<Humanoid, ItemData>("m_leftItem");

		public static void Prefix(Humanoid __instance, ItemData item, bool triggerEquipEffects)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			if (!((Object)(object)__instance != (Object)(object)Player.m_localPlayer) && item != null && (int)item.m_shared.m_itemType == 3 && leftItemRef.Invoke(__instance) == null)
			{
				ItemData val = FindBestShield(__instance);
				if (val != null)
				{
					__instance.EquipItem(val, triggerEquipEffects);
				}
			}
		}

		private static ItemData FindBestShield(Humanoid player)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Invalid comparison between Unknown and I4
			ItemData val = null;
			foreach (ItemData allItem in player.GetInventory().GetAllItems())
			{
				if ((int)allItem.m_shared.m_itemType == 5 && (val == null || allItem.GetBlockPower(((Character)player).GetSkillFactor((SkillType)6)) > val.GetBlockPower(((Character)player).GetSkillFactor((SkillType)6))))
				{
					val = allItem;
				}
			}
			return val;
		}
	}

	private readonly Harmony harmony = new Harmony("com.yourname.autoequipshield");

	private void Awake()
	{
		harmony.PatchAll();
	}
}