Decompiled source of MagnetiteBroochPlus v1.0.0

HKSSBeastShardCollection.dll

Decompiled 2 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using TeamCherry.Localization;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HKSSBeastShardCollection")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HKSSBeastShardCollection")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("0f23ac54-3faa-4577-88e3-cf895f5f3756")]
[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 MagnetiteBroochAttractsShellShards;

[BepInPlugin("com.MarxRhett.HKSSShellShardCollection", "HKSSShellShardCollection", "1.0.0")]
public class HKSSShellShardCollection : BaseUnityPlugin
{
	private InventoryToolCrestList crestList;

	private Dictionary<InventoryToolCrestSlot, ToolBase> lastEquippedTools = new Dictionary<InventoryToolCrestSlot, ToolBase>();

	private bool hooked = false;

	public bool magnetActive = false;

	public static HKSSShellShardCollection Instance { get; private set; }

	private void Awake()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Expected O, but got Unknown
		Instance = this;
		Harmony val = new Harmony("com.Marxrhett.hkss.shellshardcollection");
		val.PatchAll();
	}

	private void Update()
	{
		if ((Object)(object)crestList == (Object)null)
		{
			crestList = Object.FindFirstObjectByType<InventoryToolCrestList>();
			if ((Object)(object)crestList != (Object)null)
			{
				HookIntoCrestList();
			}
		}
		else
		{
			if (!hooked)
			{
				return;
			}
			foreach (InventoryToolCrestSlot slot in crestList.CurrentCrest.GetSlots())
			{
				ToolBase equippedItem = (ToolBase)(object)slot.EquippedItem;
				if (!lastEquippedTools.TryGetValue(slot, out var value))
				{
					lastEquippedTools[slot] = equippedItem;
				}
				if ((Object)(object)equippedItem != (Object)(object)value)
				{
					string itemName = GetItemName(equippedItem);
					string itemName2 = GetItemName(value);
					if ((Object)(object)equippedItem != (Object)null && itemName.Contains("Magnetite Brooch"))
					{
						magnetActive = true;
					}
					if ((Object)(object)value != (Object)null && itemName2.Contains("Magnetite Brooch"))
					{
						magnetActive = false;
					}
					lastEquippedTools[slot] = equippedItem;
				}
			}
		}
	}

	private void HookIntoCrestList()
	{
		if ((Object)(object)crestList == (Object)null)
		{
			return;
		}
		foreach (InventoryToolCrestSlot slot in crestList.CurrentCrest.GetSlots())
		{
			ToolBase equippedItem = (ToolBase)(object)slot.EquippedItem;
			lastEquippedTools[slot] = equippedItem;
			string itemName = GetItemName(equippedItem);
			if (itemName.Contains("Magnetite Brooch"))
			{
				magnetActive = true;
			}
		}
		hooked = true;
	}

	private string GetItemName(ToolBase item)
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)item == (Object)null)
		{
			return "None";
		}
		ToolItemBasic val = (ToolItemBasic)(object)((item is ToolItemBasic) ? item : null);
		if (val != null)
		{
			LocalisedString displayName = ((ToolItem)val).DisplayName;
			return ((object)(LocalisedString)(ref displayName)).ToString();
		}
		return ((Object)item).name ?? "Unnamed";
	}
}
[HarmonyPatch(typeof(CurrencyObjectBase), "MagnetToolIsEquipped")]
public static class CurrencyObjectBase_MagnetToolIsEquipped_Patch
{
	private static bool Prefix(CurrencyObjectBase __instance, ref bool __result)
	{
		if (__instance is ShellShard)
		{
			HKSSShellShardCollection instance = HKSSShellShardCollection.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				__result = instance.magnetActive;
			}
			else
			{
				__result = false;
			}
			return false;
		}
		return true;
	}
}