Decompiled source of Extra Tool Colors v1.0.4

plugins/Extra Tool Colors/Extra Tool Colors.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GlobalSettings;
using HarmonyLib;
using HarmonyLib.Tools;
using TeamCherry.NestedFadeGroup;
using UnityEngine;
using UnityEngine.U2D;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Extra Tool Colors")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Extra Tool Colors")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("203a70ba-07f6-4d7e-bc50-ba469ac5cb42")]
[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 ExtraToolColors;

public struct ModifyMultipleToolsSetting
{
	public ConfigEntry<string> setting;

	public List<string> affectedTools;

	public ModifyMultipleToolsSetting(string section, ConfigFile file, string toolName, IEnumerable<string> affectedSettings, AcceptableValueList<string> options, string defaultValue = "NOSETTING", EventHandler settingChangedEvent = null)
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		setting = file.Bind<string>(section, toolName, defaultValue, new ConfigDescription("Changes " + toolName + " tool type", (AcceptableValueBase)(object)options, Array.Empty<object>()));
		setting.SettingChanged += settingChangedEvent;
		affectedTools = affectedSettings.ToList();
	}
}
public class ConfigManager
{
	public static List<string> internalSkillToolNames = new List<string> { "Silk Spear", "Thread Sphere", "Parry", "Silk Charge", "Silk Bomb", "Silk Boss Needle" };

	public static List<string> internalRedToolNames = new List<string>
	{
		"Straight Pin", "Tri Pin", "Sting Shard", "Tack", "Harpoon", "Shakra Ring", "Pimpilo", "Conch Drill", "Screw Attack", "Cogwork Saw",
		"Cogwork Flier", "Rosary Cannon", "Lightning Rod", "Flintstone", "Silk Snare", "Flea Brew", "Lifeblood Syringe", "Extractor"
	};

	public static List<string> internalBlueToolNames = new List<string>
	{
		"Lava Charm", "Bell Bind", "Poison Pouch", "Fractured Mask", "MultiBind", "White Ring", "Brolly Spike", "Quickbind", "Spool Extender", "Reserve Bind",
		"Revenge Crystal", "Thief Claw", "Zap Imbuement", "Quick Sling", "Maggot Charm", "Longneedle", "Wisp Lantern", "Flea Charm", "Pinstress Tool"
	};

	public static List<string> internalYellowToolNames = new List<string>
	{
		"Compass", "Bone Necklace", "RosaryMagnet", "Weighted Anklet", "Barbed Wire", "Dead Mans Purse", "Shell Satchel", "Magnetite Dice", "Scuttlebrace", "Wallcling",
		"Musician Charm", "Sprintmaster", "Thief Charm"
	};

	public static AcceptableValueList<string> attackToolOptions = new AcceptableValueList<string>(new string[3] { "White", "Red", "Pink" });

	public static string attackToolOptionsString = "(White, Red, Pink)";

	public static AcceptableValueList<string> toolOptions = new AcceptableValueList<string>(new string[8] { "White", "Red", "Blue", "Yellow", "Green", "Purple", "Orange", "Pink" });

	public static string toolOptionsString = "(White, Red, Blue, Yellow, Green, Purple, Orange, Pink)";

	public ConfigFile file;

	public string title;

	public Dictionary<string, ConfigEntry<string>> toolSettings;

	public List<ModifyMultipleToolsSetting> modifyMultiples;

	public ConfigEntry<bool> modifyMosscreepsAsOne;

	public ConfigEntry<bool> modifyCurveClawsAsOne;

	public ConfigEntry<bool> modifyDazzleBindsAsOne;

	public List<ConfigEntry<string>> toolTypes;

	public Dictionary<string, ToolItemType> changes;

	public List<Tuple<string, List<string>, AcceptableValueList<string>, string>> ModifyMultipleAsOne { get; private set; } = new List<Tuple<string, List<string>, AcceptableValueList<string>, string>>
	{
		Tuple.Create<string, List<string>, AcceptableValueList<string>, string>("WebShot", new List<string> { "WebShot Weaver", "WebShot Architect", "WebShot Forge" }, attackToolOptions, "Red"),
		Tuple.Create<string, List<string>, AcceptableValueList<string>, string>("Mosscreep", new List<string> { "Mosscreep Tool 1", "Mosscreep Tool 2" }, toolOptions, "Blue"),
		Tuple.Create<string, List<string>, AcceptableValueList<string>, string>("Curve Claws", new List<string> { "Curve Claws", "Curve Claws Upgraded" }, attackToolOptions, "Red"),
		Tuple.Create<string, List<string>, AcceptableValueList<string>, string>("Dazzle Bind", new List<string> { "Dazzle Bind", "Dazzle Bind Upgraded" }, toolOptions, "Blue")
	};


	public Dictionary<string, ToolItemType> RealChanges { get; private set; }

	public static List<string> InternalIntToolNames(int i)
	{
		return i switch
		{
			0 => internalSkillToolNames, 
			1 => internalRedToolNames, 
			2 => internalBlueToolNames, 
			3 => internalYellowToolNames, 
			_ => new List<string>(), 
		};
	}

	public void SetChange(string toolName, ToolItemType type)
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected I4, but got Unknown
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		if (!changes.ContainsKey(toolName))
		{
			changes.Add(toolName, type);
		}
		else
		{
			changes[toolName] = type;
		}
		bool flag = RealChanges.ContainsKey(toolName);
		bool flag2 = InternalIntToolNames((int)type).Contains(toolName);
		foreach (Tuple<string, List<string>, AcceptableValueList<string>, string> item in ModifyMultipleAsOne)
		{
			ToolItemType? val = ConvertStringToToolType(item.Item4);
			if (val.HasValue && item.Item2.Contains(toolName) && val.Value == type)
			{
				flag2 = true;
				break;
			}
		}
		switch ((flag ? 2 : 0) + (flag2 ? 1 : 0))
		{
		case 0:
			RealChanges.Add(toolName, type);
			Console.WriteLine(toolName);
			break;
		case 1:
			break;
		case 2:
			RealChanges[toolName] = type;
			break;
		case 3:
			RealChanges.Remove(toolName);
			break;
		}
	}

	public void RemoveChange(string toolName)
	{
		if (changes.ContainsKey(toolName))
		{
			changes.Remove(toolName);
		}
		if (RealChanges.ContainsKey(toolName))
		{
			RealChanges.Remove(toolName);
		}
	}

	public ConfigManager(ConfigFile configFile, string section = "ExtraToolColorsTransmog")
	{
		file = configFile;
		title = section;
		changes = new Dictionary<string, ToolItemType>();
	}

	public void Init()
	{
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Expected O, but got Unknown
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Expected O, but got Unknown
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Expected O, but got Unknown
		//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ad: Expected O, but got Unknown
		modifyMultiples = new List<ModifyMultipleToolsSetting>();
		toolSettings = new Dictionary<string, ConfigEntry<string>>();
		foreach (Tuple<string, List<string>, AcceptableValueList<string>, string> item in ModifyMultipleAsOne)
		{
			modifyMultiples.Add(new ModifyMultipleToolsSetting(title, file, item.Item1, item.Item2, item.Item3, item.Item4, MultipleSettingChangedEvent));
		}
		foreach (string internalSkillToolName in internalSkillToolNames)
		{
			toolSettings.Add(internalSkillToolName, file.Bind<string>(title, internalSkillToolName, "White", new ConfigDescription("Changes " + internalSkillToolName + " tool type", (AcceptableValueBase)(object)attackToolOptions, Array.Empty<object>())));
			toolSettings[internalSkillToolName].SettingChanged += SingleSettingChangedEvent;
		}
		foreach (string internalRedToolName in internalRedToolNames)
		{
			toolSettings.Add(internalRedToolName, file.Bind<string>(title, internalRedToolName, "Red", new ConfigDescription("Changes " + internalRedToolName + " tool type", (AcceptableValueBase)(object)attackToolOptions, Array.Empty<object>())));
			toolSettings[internalRedToolName].SettingChanged += SingleSettingChangedEvent;
		}
		foreach (string internalBlueToolName in internalBlueToolNames)
		{
			toolSettings.Add(internalBlueToolName, file.Bind<string>(title, internalBlueToolName, "Blue", new ConfigDescription("Changes " + internalBlueToolName + " tool type", (AcceptableValueBase)(object)toolOptions, Array.Empty<object>())));
			toolSettings[internalBlueToolName].SettingChanged += SingleSettingChangedEvent;
		}
		foreach (string internalYellowToolName in internalYellowToolNames)
		{
			toolSettings.Add(internalYellowToolName, file.Bind<string>(title, internalYellowToolName, "Yellow", new ConfigDescription("Changes " + internalYellowToolName + " tool type", (AcceptableValueBase)(object)toolOptions, Array.Empty<object>())));
			toolSettings[internalYellowToolName].SettingChanged += SingleSettingChangedEvent;
		}
		changes = GetAllEntries();
		RealChanges = GetAllRealChangedEntries();
	}

	protected virtual void SingleSettingChangedEvent(object sender, EventArgs e)
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		if (!(sender is ConfigEntry<string>))
		{
			return;
		}
		ConfigEntry<string> val = sender as ConfigEntry<string>;
		string text = UnProcessSettingName(((ConfigEntryBase)val).Definition.Key);
		if (text != null)
		{
			ToolItemType? entryByName = GetEntryByName(text);
			if (entryByName.HasValue)
			{
				SetChange(text, entryByName.Value);
			}
		}
	}

	protected virtual void MultipleSettingChangedEvent(object sender, EventArgs e)
	{
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		if (!(sender is ConfigEntry<string>) && !(sender is ConfigEntry<bool>))
		{
			return;
		}
		foreach (ModifyMultipleToolsSetting modifyMultiple in modifyMultiples)
		{
			if (modifyMultiple.setting != sender as ConfigEntry<string>)
			{
				continue;
			}
			ToolItemType? val = ConvertStringToToolType(modifyMultiple.setting.Value);
			if (val.HasValue)
			{
				foreach (string affectedTool in modifyMultiple.affectedTools)
				{
					SetChange(affectedTool, val.Value);
				}
				continue;
			}
			foreach (string affectedTool2 in modifyMultiple.affectedTools)
			{
				RemoveChange(affectedTool2);
			}
		}
	}

	public Dictionary<string, ToolItemType> GetAllEntries()
	{
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		Dictionary<string, ToolItemType> dictionary = new Dictionary<string, ToolItemType>();
		foreach (string key in toolSettings.Keys)
		{
			ToolItemType? entryByName = GetEntryByName(key);
			if (entryByName.HasValue)
			{
				dictionary.Add(key, entryByName.Value);
			}
		}
		return dictionary;
	}

	public Dictionary<string, ToolItemType> GetAllRealChangedEntries()
	{
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Expected I4, but got Unknown
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		Dictionary<string, ToolItemType> dictionary = new Dictionary<string, ToolItemType>();
		foreach (string key in toolSettings.Keys)
		{
			ToolItemType? entryByName = GetEntryByName(key);
			if (entryByName.HasValue && !InternalIntToolNames((int)entryByName.Value).Contains(key))
			{
				dictionary.Add(key, entryByName.Value);
			}
		}
		return dictionary;
	}

	public ToolItemType? GetEntryByName(string toolName)
	{
		if (!toolSettings.ContainsKey(toolName))
		{
			return null;
		}
		foreach (ModifyMultipleToolsSetting modifyMultiple in modifyMultiples)
		{
			if (modifyMultiple.affectedTools.Contains(toolName) && modifyMultiple.setting.Value != (string)((ConfigEntryBase)modifyMultiple.setting).DefaultValue)
			{
				return ConvertStringToToolType(modifyMultiple.setting.Value);
			}
		}
		string value = toolSettings[toolName].Value;
		if (value == (string)((ConfigEntryBase)toolSettings[toolName]).DefaultValue)
		{
			return null;
		}
		return ConvertStringToToolType(value);
	}

	public static ToolItemType? ConvertStringToToolType(string str)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		string input = str.ToUpper();
		if (Regex.IsMatch(input, "4|(GREEN)|((?=.*((BLUE)|(DEFEND)|1)).*((YELLOW)|(EXPLORE)|2))"))
		{
			return ExtraToolColors.Green;
		}
		if (Regex.IsMatch(input, "5|(PURPLE)|((?=.*((BLUE)|(DEFEND)|1)).*((RED)|(ATTACK)|0))"))
		{
			return ExtraToolColors.Purple;
		}
		if (Regex.IsMatch(input, "6|(ORANGE)|((?=.*((YELLOW)|(EXPLORE)|2)).*((RED)|(ATTACK)|0))"))
		{
			return ExtraToolColors.Orange;
		}
		if (Regex.IsMatch(input, "7|(PINK)|((?=.*((WHITE)|(SKILL)|3)).*((RED)|(ATTACK)|0))"))
		{
			return ExtraToolColors.Pink;
		}
		if (Regex.IsMatch(input, "0|(RED)|(ATTACK)"))
		{
			return (ToolItemType)0;
		}
		if (Regex.IsMatch(input, "1|(BLUE)|(DEFEND)"))
		{
			return (ToolItemType)1;
		}
		if (Regex.IsMatch(input, "2|(YELLOW)|(EXPLORE)"))
		{
			return (ToolItemType)2;
		}
		if (Regex.IsMatch(input, "3|(SKILL)|(WHITE)"))
		{
			return (ToolItemType)3;
		}
		return null;
	}

	public static string ProcessSettingName(string settingName)
	{
		return settingName.Replace(' ', '_');
	}

	public static string UnProcessSettingName(string settingName)
	{
		return settingName.Replace('_', ' ');
	}

	public void Randomize(int seed)
	{
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		Random random = new Random(seed);
		foreach (KeyValuePair<string, ConfigEntry<string>> toolSetting in toolSettings)
		{
			ToolItemType? entryByName = GetEntryByName(toolSetting.Key);
			if (entryByName.HasValue)
			{
				int num = ((!ExtraToolColors.AttackOnlyTypes.Contains(entryByName.Value)) ? random.Next(8) : ((int)ExtraToolColors.AttackOnlyTypes[random.Next(ExtraToolColors.AttackOnlyTypes.Count)]));
				((ConfigEntryBase)toolSetting.Value).SetSerializedValue(ExtraToolColors.toolItemTypeNames[num]);
				SetChange(toolSetting.Key, (ToolItemType)num);
			}
		}
		foreach (ModifyMultipleToolsSetting modifyMultiple in modifyMultiples)
		{
			ToolItemType? val = ConvertStringToToolType((string)((ConfigEntryBase)modifyMultiple.setting).DefaultValue);
			if (!val.HasValue)
			{
				continue;
			}
			int num2 = ((!ExtraToolColors.AttackOnlyTypes.Contains(val.Value)) ? random.Next(8) : ((int)ExtraToolColors.AttackOnlyTypes[random.Next(ExtraToolColors.AttackOnlyTypes.Count)]));
			((ConfigEntryBase)modifyMultiple.setting).SetSerializedValue(ExtraToolColors.toolItemTypeNames[num2]);
			foreach (string affectedTool in modifyMultiple.affectedTools)
			{
				SetChange(affectedTool, (ToolItemType)num2);
			}
		}
	}

	public void ResetToDefaults()
	{
		changes.Clear();
		RealChanges.Clear();
		foreach (KeyValuePair<string, ConfigEntry<string>> toolSetting in toolSettings)
		{
			((ConfigEntryBase)toolSetting.Value).BoxedValue = ((ConfigEntryBase)toolSetting.Value).DefaultValue;
		}
		foreach (ModifyMultipleToolsSetting modifyMultiple in modifyMultiples)
		{
			((ConfigEntryBase)modifyMultiple.setting).BoxedValue = ((ConfigEntryBase)modifyMultiple.setting).DefaultValue;
		}
	}
}
public struct ChangedSlot
{
	public ToolItemType OriginalType;

	public int Occurance;

	public ToolItemType NewType;

	public ChangedSlot(ToolItemType origninalType, int occurance, ToolItemType newType)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		OriginalType = origninalType;
		Occurance = occurance;
		NewType = newType;
	}
}
public struct ChangedSlotList
{
	public List<ChangedSlot> slots;

	public ToolItemType Match(ToolItemType originalType, int occurances)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		IEnumerable<ChangedSlot> source = slots.Where((ChangedSlot slot) => slot.OriginalType == originalType && slot.Occurance == occurances);
		return (source.Count() > 0) ? source.First().NewType : originalType;
	}

	public ToolItemType MatchAndPop(ToolItemType originalType, int occurances)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		IEnumerable<ChangedSlot> source = slots.Where((ChangedSlot slot) => slot.OriginalType == originalType && slot.Occurance == occurances);
		if (source.Count() > 0)
		{
			ChangedSlot item = source.First();
			slots.Remove(item);
			return item.NewType;
		}
		return originalType;
	}

	public ChangedSlotList(ToolItemType[] originalItemTypes, int[] occurances, ToolItemType[] newItemTypes)
	{
		slots = new List<ChangedSlot>();
		int num = Math.Min(Math.Min(originalItemTypes.Length, occurances.Length), newItemTypes.Length);
		for (int i = 0; i < num; i++)
		{
			slots.Add(new ChangedSlot(originalItemTypes[i], occurances[i], newItemTypes[i]));
		}
	}

	public void ReplaceOrAdd(ToolItemType originalType, int occurance, ToolItemType newType)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		int num = slots.FindIndex((ChangedSlot slot) => slot.OriginalType == originalType && slot.Occurance == occurance);
		if (num >= 0)
		{
			slots.RemoveAt(num);
		}
		slots.Add(new ChangedSlot(originalType, occurance, newType));
	}
}
public struct SlotIconChanger
{
	private readonly InventoryToolCrestSlot slot;

	private NestedFadeGroupSpriteRenderer slotIcon;

	private readonly AttackToolBinding attackBinding;

	public ToolItemType Type => slot.Type;

	public bool SetSprite(Dictionary<AttackToolBinding, Sprite> sprite)
	{
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)slot == (Object)null)
		{
			return false;
		}
		if (!((Behaviour)slot).isActiveAndEnabled || Object.op_Implicit((Object)(object)slot.EquippedItem) || slot.IsLocked)
		{
			return true;
		}
		if (!Object.op_Implicit((Object)(object)slotIcon))
		{
			slotIcon = Traverse.Create((object)slot).Field("slotTypeIcon").GetValue<NestedFadeGroupSpriteRenderer>();
		}
		slotIcon.Sprite = sprite[attackBinding];
		return true;
	}

	public SlotIconChanger(InventoryToolCrestSlot Slot, AttackToolBinding? AttackBinding)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		slot = Slot;
		slotIcon = Traverse.Create((object)slot).Field("slotTypeIcon").GetValue<NestedFadeGroupSpriteRenderer>();
		attackBinding = (AttackToolBinding)(AttackBinding.HasValue ? ((int)AttackBinding.Value) : 0);
	}

	public int InList(List<SlotIconChanger> list)
	{
		InventoryToolCrestSlot s = slot;
		return list.FindIndex((SlotIconChanger changer) => (Object)(object)changer.slot == (Object)(object)s);
	}
}
[BepInPlugin("com.archdodo.ExtraToolColors", "Extra Tool Colors", "1.0.3")]
public class ExtraToolColors : BaseUnityPlugin
{
	public const int N_TYPES = 8;

	public static readonly ToolItemType Green = (ToolItemType)4;

	public static readonly ToolItemType Purple = (ToolItemType)5;

	public static readonly ToolItemType Orange = (ToolItemType)6;

	public static readonly ToolItemType Pink = (ToolItemType)7;

	public static readonly ToolItemType[] extraTypes = (ToolItemType[])(object)new ToolItemType[4]
	{
		(ToolItemType)(int)Green,
		(ToolItemType)(int)Purple,
		(ToolItemType)(int)Orange,
		(ToolItemType)(int)Pink
	};

	public static readonly string[] toolItemTypeNames = new string[8] { "Attack", "Defend", "Explore", "Skill", "Defend/Explore", "Attack/Defend", "Attack/Explore", "Attack/Skill" };

	private static readonly Color[] toolTypeColors = (Color[])(object)new Color[4]
	{
		new Color(0.3f, 1f, 0.3f, 1f),
		new Color(0.8f, 0.4f, 1f, 1f),
		new Color(1f, 0.5f, 0.1f, 1f),
		new Color(0.95f, 0.54f, 0.68f, 1f)
	};

	public static readonly List<int> AdditionalAttackTypes = new List<int> { 5, 6, 7 };

	public static readonly List<ToolItemType> AttackOnlyTypes = new List<ToolItemType>
	{
		(ToolItemType)0,
		(ToolItemType)3,
		Pink
	};

	private static AssetBundle spriteBundle;

	internal static ManualLogSource Log;

	private static Sprite[] ExtraHeadersSprites;

	private static readonly Harmony harmony = new Harmony("com.archdodo.ExtraToolColors");

	public static Dictionary<string, ChangedSlotList> ChangedSlots = new Dictionary<string, ChangedSlotList>
	{
		{
			"Hunter",
			new ChangedSlotList((ToolItemType[])(object)new ToolItemType[0], new int[0], (ToolItemType[])(object)new ToolItemType[0])
		},
		{
			"Reaper",
			new ChangedSlotList((ToolItemType[])(object)new ToolItemType[0], new int[0], (ToolItemType[])(object)new ToolItemType[0])
		},
		{
			"Wanderer",
			new ChangedSlotList((ToolItemType[])(object)new ToolItemType[0], new int[0], (ToolItemType[])(object)new ToolItemType[0])
		},
		{
			"Warrior",
			new ChangedSlotList((ToolItemType[])(object)new ToolItemType[0], new int[0], (ToolItemType[])(object)new ToolItemType[0])
		},
		{
			"Witch",
			new ChangedSlotList((ToolItemType[])(object)new ToolItemType[0], new int[0], (ToolItemType[])(object)new ToolItemType[0])
		},
		{
			"Toolmaster",
			new ChangedSlotList((ToolItemType[])(object)new ToolItemType[0], new int[0], (ToolItemType[])(object)new ToolItemType[0])
		},
		{
			"Spell",
			new ChangedSlotList((ToolItemType[])(object)new ToolItemType[0], new int[0], (ToolItemType[])(object)new ToolItemType[0])
		}
	};

	public static bool ChangeHunterUpgradesWithBase = true;

	private static readonly Expression<Func<ToolItemType, ToolItemType, bool>> m_ToolCompatability = (ToolItemType type1, ToolItemType type2) => ToolCompatability(type1, type2);

	private static readonly Expression<Func<ToolItem, ToolItemType>> m_GetOldToolItemType = (ToolItem tool) => GetOldToolItemType(tool);

	internal static ConfigManager configManager;

	private static readonly RuntimeAnimatorController[] toolSlotAnimatorControllers = (RuntimeAnimatorController[])(object)new RuntimeAnimatorController[8];

	public static List<int>[] ToolCompatabilityGragh { get; private set; } = new List<int>[8]
	{
		new List<int> { 5, 6, 7 },
		new List<int> { 4, 5 },
		new List<int> { 4, 6 },
		new List<int> { 7 },
		new List<int> { 1, 2, 5, 6 },
		new List<int> { 0, 1, 4, 6, 7 },
		new List<int> { 0, 2, 4, 5, 7 },
		new List<int> { 0, 3, 5, 6 }
	};


	public static Dictionary<string, ToolItemType> ChangedTools => configManager.changes;

	public static Dictionary<string, ToolItemType> OriginalTypes { get; private set; } = new Dictionary<string, ToolItemType>();


	public static List<SlotIconChanger> SlotIcons { get; private set; } = new List<SlotIconChanger>();


	public static Dictionary<string, ToolItemType[]> OriginalSlots { get; private set; } = new Dictionary<string, ToolItemType[]>();


	public static Dictionary<ToolItemType, Dictionary<AttackToolBinding, Sprite>> ExtraColorsSlotSprites { get; private set; }

	public static PluginInfo PInfo { get; private set; }

	public static Dictionary<string, ToolItemType> GetChangedTools()
	{
		return configManager.RealChanges;
	}

	public static bool ToolCompatability(ToolItemType type1, ToolItemType type2)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Expected I4, but got Unknown
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Expected I4, but got Unknown
		int num = (int)type1;
		int num2 = (int)type2;
		if (num == num2)
		{
			return true;
		}
		return ToolCompatabilityGragh[num].Contains(num2);
	}

	public static int ExtraColorsGetAvailableSlotCount(IEnumerable<InventoryToolCrestSlot> slots, ToolItemType toolType, bool checkEmpty)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		return slots.Count((InventoryToolCrestSlot slot) => !slot.IsLocked && ToolCompatability(slot.Type, toolType) && (!checkEmpty || (Object)(object)slot.EquippedItem == (Object)null));
	}

	public static IEnumerable<InventoryToolCrestSlot> ExtraColorsGetAvailableSlots(IEnumerable<InventoryToolCrestSlot> slots, ToolItemType toolType)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		slots = slots.Where((InventoryToolCrestSlot slot) => !slot.IsLocked && ToolCompatability(slot.Type, toolType));
		return slots.Any((InventoryToolCrestSlot slot) => !Object.op_Implicit((Object)(object)slot.EquippedItem)) ? slots.Where((InventoryToolCrestSlot slot) => !Object.op_Implicit((Object)(object)slot.EquippedItem)) : slots;
	}

	public static InventoryToolCrestSlot ExtraColorsGetAvailableSlot(IEnumerable<InventoryToolCrestSlot> slots, ToolItemType toolType)
	{
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		return ExtraColorsGetAvailableSlots(slots, toolType).First();
	}

	public static int GetAvailableSlotCount(IEnumerable<InventoryToolCrestSlot> slots, ToolItemType toolType, bool checkEmpty)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		return slots.Count((InventoryToolCrestSlot slot) => !slot.IsLocked && slot.Type == toolType && (!checkEmpty || (Object)(object)slot.EquippedItem == (Object)null));
	}

	public static ToolItemType GetOldToolItemType(ToolItem tool)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		return (ToolItemType)((!OriginalTypes.ContainsKey(tool.name)) ? ((tool.Type != Pink) ? ((int)tool.Type) : ((tool is ToolItemSkill) ? 3 : 0)) : ((int)OriginalTypes[tool.name]));
	}

	private void Awake()
	{
		PInfo = ((BaseUnityPlugin)this).Info;
		configManager = new ConfigManager(((BaseUnityPlugin)this).Config);
		configManager.Init();
		if (ChangeHunterUpgradesWithBase)
		{
			ChangedSlots.Add("Hunter_v2", ChangedSlots["Hunter"]);
			ChangedSlots.Add("Hunter_v3", ChangedSlots["Hunter"]);
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Extra Tool Colors loaded and initialized");
		Log = ((BaseUnityPlugin)this).Logger;
		LoadSpritesFromAssetBundle();
		HarmonyFileLog.Enabled = true;
		harmony.PatchAll(typeof(ExtraToolColors));
	}

	private void LateUpdate()
	{
		CollectionExtensions.Do<SlotIconChanger>((IEnumerable<SlotIconChanger>)SlotIcons, (Action<SlotIconChanger>)delegate(SlotIconChanger changer)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			changer.SetSprite(ExtraColorsSlotSprites[changer.Type]);
		});
	}

	private void OnDestroy()
	{
		configManager.file.Save();
		configManager = null;
		OriginalTypes.Clear();
		SlotIcons.Clear();
		spriteBundle = null;
		harmony.UnpatchSelf();
	}

	public static void SetupCustomPinkTool(ToolItem tool, bool hasLimitedUses)
	{
		SetupCustomPinkTool(tool.name, hasLimitedUses);
	}

	public static void SetupCustomPinkTool(string toolName, bool hasLimitedUses)
	{
		OriginalTypes.Add(toolName, (ToolItemType)((!hasLimitedUses) ? 3 : 0));
	}

	private static void LoadSpritesFromAssetBundle()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)spriteBundle == (Object)null)
		{
			string text = Path.Combine(Path.GetDirectoryName(PInfo.Location), "extra_tool_colors_sprites");
			if (!File.Exists(text))
			{
				Log.LogError((object)("Could not find AssetBundle at: \"" + text + "\""));
				return;
			}
			spriteBundle = AssetBundle.LoadFromFile(text);
		}
		SpriteAtlas atlas = spriteBundle.LoadAsset<SpriteAtlas>("Extra Colors Sprites");
		ExtraHeadersSprites = (Sprite[])(object)new Sprite[4]
		{
			LoadSprite("GreenListHeader"),
			LoadSprite("PurpleListHeader"),
			LoadSprite("OrangeListHeader"),
			LoadSprite("PinkListHeader")
		};
		ExtraColorsSlotSprites = new Dictionary<ToolItemType, Dictionary<AttackToolBinding, Sprite>>
		{
			{
				Green,
				new Dictionary<AttackToolBinding, Sprite>
				{
					{
						(AttackToolBinding)0,
						LoadSprite("Green Slot")
					},
					{
						(AttackToolBinding)1,
						LoadSprite("Green Slot")
					},
					{
						(AttackToolBinding)2,
						LoadSprite("Green Slot")
					}
				}
			},
			{
				Purple,
				new Dictionary<AttackToolBinding, Sprite>
				{
					{
						(AttackToolBinding)0,
						LoadSprite("Purple Slot")
					},
					{
						(AttackToolBinding)1,
						LoadSprite("Purple Slot Up")
					},
					{
						(AttackToolBinding)2,
						LoadSprite("Purple Slot Down")
					}
				}
			},
			{
				Orange,
				new Dictionary<AttackToolBinding, Sprite>
				{
					{
						(AttackToolBinding)0,
						LoadSprite("Orange Slot")
					},
					{
						(AttackToolBinding)1,
						LoadSprite("Orange Slot Up")
					},
					{
						(AttackToolBinding)2,
						LoadSprite("Orange Slot Down")
					}
				}
			},
			{
				Pink,
				new Dictionary<AttackToolBinding, Sprite>
				{
					{
						(AttackToolBinding)0,
						LoadSprite("Pink Slot")
					},
					{
						(AttackToolBinding)1,
						LoadSprite("Pink Slot Up")
					},
					{
						(AttackToolBinding)2,
						LoadSprite("Pink Slot Down")
					}
				}
			}
		};
		Sprite LoadSprite(string name)
		{
			return atlas.GetSprite(name);
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(UI), "GetToolTypeColor")]
	public static bool GetToolTypeColorPrefix(ToolItemType type, ref Color __result)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Expected I4, but got Unknown
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		int num = (int)type;
		if (num > 3)
		{
			__result = toolTypeColors[num - 4];
			return false;
		}
		return true;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(InventoryItemTool), "SetData")]
	public static void SetDataPrefix(ref ToolItem newItemData, InventoryItemTool __instance, RuntimeAnimatorController[] ___slotAnimatorControllers)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Invalid comparison between Unknown and I4
		if (___slotAnimatorControllers.Length >= 5 || (int)newItemData.Type <= 3)
		{
			return;
		}
		if ((Object)(object)toolSlotAnimatorControllers[0] == (Object)null)
		{
			___slotAnimatorControllers.CopyTo(toolSlotAnimatorControllers, 0);
			for (int i = 0; i < 4; i++)
			{
				toolSlotAnimatorControllers[i + 4] = Object.Instantiate<RuntimeAnimatorController>(toolSlotAnimatorControllers[i]);
			}
		}
		Traverse.Create((object)__instance).Field("slotAnimatorControllers").SetValue(toolSlotAnimatorControllers.Clone());
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(InventoryItemToolManager), "GetGridSections")]
	public static void GetGridSectionsPrefix(ref NestedFadeGroupSpriteRenderer[] ___listSectionHeaders, List<ToolItem> items)
	{
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: Unknown result type (might be due to invalid IL or missing references)
		if (___listSectionHeaders.Length < 5)
		{
			NestedFadeGroupSpriteRenderer val = Object.Instantiate<NestedFadeGroupSpriteRenderer>(___listSectionHeaders[3], ((Component)___listSectionHeaders[0]).transform.parent);
			NestedFadeGroupSpriteRenderer val2 = Object.Instantiate<NestedFadeGroupSpriteRenderer>(___listSectionHeaders[2], ((Component)___listSectionHeaders[0]).transform.parent);
			NestedFadeGroupSpriteRenderer val3 = Object.Instantiate<NestedFadeGroupSpriteRenderer>(___listSectionHeaders[3], ((Component)___listSectionHeaders[0]).transform.parent);
			NestedFadeGroupSpriteRenderer val4 = Object.Instantiate<NestedFadeGroupSpriteRenderer>(___listSectionHeaders[3], ((Component)___listSectionHeaders[0]).transform.parent);
			NestedFadeGroupSpriteRenderer[] array = (NestedFadeGroupSpriteRenderer[])(object)new NestedFadeGroupSpriteRenderer[8]
			{
				default(NestedFadeGroupSpriteRenderer),
				default(NestedFadeGroupSpriteRenderer),
				default(NestedFadeGroupSpriteRenderer),
				default(NestedFadeGroupSpriteRenderer),
				val,
				val3,
				val2,
				val4
			};
			___listSectionHeaders.CopyTo(array, 0);
			for (int i = 0; i < 4; i++)
			{
				Extensions.SetScaleMatching(((Component)array[i + 4]).transform, 1.5f);
				array[i + 4].Sprite = ExtraHeadersSprites[i];
			}
			___listSectionHeaders = array;
		}
		foreach (ToolItem item in items)
		{
			if (GetChangedTools().ContainsKey(item.name))
			{
				if (!OriginalTypes.ContainsKey(item.name))
				{
					OriginalTypes.Add(item.name, item.Type);
				}
				Traverse.Create((object)item).Field("type").SetValue((object)GetChangedTools()[item.name]);
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(InventoryItemToolManager), "GetGridSections")]
	public static void GetGridSectionsPostfix(InventoryItemGrid ___toolList, NestedFadeGroupSpriteRenderer[] ___listSectionHeaders, List<InventoryItemTool> selectableItems, ref List<GridSection> __result)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		List<GridSection> list = new List<GridSection>();
		int i;
		for (i = 4; i < 8; i++)
		{
			list.Add(new GridSection
			{
				Header = ((Component)___listSectionHeaders[i]).transform,
				Items = selectableItems.Where((InventoryItemTool item) => (int)item.ToolType == i).Cast<InventoryItemSelectableDirectional>().ToList()
			});
		}
		___toolList.Setup(list);
		__result.AddRange(list);
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(InventoryToolCrest), "Setup")]
	public static void CrestSetupPrefix(InventoryToolCrest __instance, ToolCrest newCrestData, ref InventoryToolCrestSlot[] ___templateSlots)
	{
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: 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)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		Traverse t = Traverse.CreateWithType("InventoryToolCrest").Field("TOOL_TYPES");
		if (T().Length < 5)
		{
			ToolItemType[] array = (ToolItemType[])(object)new ToolItemType[8];
			T().CopyTo(array, 0);
			extraTypes.CopyTo(array, 4);
			t.SetValue((object)array);
		}
		Traverse val = Traverse.Create((object)__instance).Field("templateSlots");
		if ((val.GetValue() as InventoryToolCrestSlot[]).Length < 5)
		{
			InventoryToolCrestSlot[] array2 = (InventoryToolCrestSlot[])(object)new InventoryToolCrestSlot[8];
			___templateSlots.CopyTo(array2, 0);
			for (int i = 4; i < 8; i++)
			{
				int num = i switch
				{
					4 => 1, 
					7 => 3, 
					_ => 0, 
				};
				array2[i] = Object.Instantiate<InventoryToolCrestSlot>(array2[num], ((Component)array2[num]).transform.parent);
				((Object)array2[i]).name = toolItemTypeNames[i] + " Slot";
				SlotInfo slotInfo = array2[i].SlotInfo;
				slotInfo.Type = extraTypes[i - 4];
				array2[i].SlotInfo = slotInfo;
				Traverse.Create((object)array2[i]).Field("slotTypeSprite").SetValue((object)ExtraColorsSlotSprites[(ToolItemType)i][(AttackToolBinding)0]);
			}
			___templateSlots = array2;
		}
		int[] array3 = new int[8];
		if (ChangedSlots.ContainsKey(newCrestData.name))
		{
			ToolItemType[] array4 = slotTypes(newCrestData.Slots);
			if (!OriginalSlots.ContainsKey(newCrestData.name))
			{
				OriginalSlots.Add(newCrestData.name, slotTypes(newCrestData.Slots));
			}
			else
			{
				array4 = OriginalSlots[newCrestData.name];
			}
			for (int j = 0; j < array4.Length; j++)
			{
				array3[(int)array4[j]]++;
				newCrestData.Slots[j].Type = ChangedSlots[newCrestData.name].Match(array4[j], array3[(int)array4[j]]);
			}
		}
		ToolItemType[] T()
		{
			return t.GetValue() as ToolItemType[];
		}
		static ToolItemType[] slotTypes(SlotInfo[] Slots)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected I4, but got Unknown
			ToolItemType[] array5 = (ToolItemType[])(object)new ToolItemType[Slots.Length];
			for (int k = 0; k < array5.Length; k++)
			{
				array5[k] = (ToolItemType)(int)Slots[k].Type;
			}
			return array5;
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(InventoryToolCrest), "Setup")]
	public static void AddSlotsToChangerList(List<InventoryToolCrestSlot> ___activeSlots, List<SlotInfo> ___activeSlotsData)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Invalid comparison between Unknown and I4
		//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)
		for (int i = 0; i < ___activeSlots.Count; i++)
		{
			if ((int)___activeSlots[i].Type > 3)
			{
				SlotIconChanger item = new SlotIconChanger(___activeSlots[i], ___activeSlotsData[i].AttackBinding);
				int num = item.InList(SlotIcons);
				if (num >= 0)
				{
					SlotIcons.RemoveAt(num);
				}
				SlotIcons.Add(item);
			}
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(ToolItemList), "SortByType")]
	public static bool SortByTypePrefix(ToolItemList __instance)
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Expected I4, but got Unknown
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Expected I4, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Expected I4, but got Unknown
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected I4, but got Unknown
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		ToolItemType[] array = new ToolItemType[8];
		RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
		array[4] = (ToolItemType)(int)Green;
		array[5] = (ToolItemType)(int)Purple;
		array[6] = (ToolItemType)(int)Orange;
		array[7] = (ToolItemType)(int)Pink;
		ToolItemType[] array2 = (ToolItemType[])(object)array;
		Dictionary<ToolItemType, List<ToolItem>> dictionary = new Dictionary<ToolItemType, List<ToolItem>>(array2.Count());
		ToolItemType[] array3 = array2;
		foreach (ToolItemType key in array3)
		{
			dictionary[key] = new List<ToolItem>();
		}
		List<ToolItem> list = Traverse.Create((object)__instance).Field("List").GetValue() as List<ToolItem>;
		foreach (ToolItem item in list)
		{
			if (!((Object)(object)item == (Object)null))
			{
				dictionary[item.Type].Add(item);
			}
		}
		list.Clear();
		ToolItemType[] array4 = array2;
		foreach (ToolItemType key2 in array4)
		{
			list.AddRange(dictionary[key2]);
		}
		return false;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(ToolItemTypeExtensions), "IsAttackType")]
	public static void IsAttackTypePostfix(ToolItemType type, ref bool __result)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected I4, but got Unknown
		__result = __result || AdditionalAttackTypes.Contains((int)type);
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(ToolItemManager), "GetBoundAttackTool", new Type[]
	{
		typeof(AttackToolBinding),
		typeof(ToolEquippedReadSource)
	})]
	public static void GetBoundAttackToolPostfix(ref ToolItem __result)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)__result != (Object)null && !AttackOnlyTypes.Contains(__result.Type))
		{
			__result = null;
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(RadialHudIcon), "UpdateDisplay")]
	public static void SetToolHudIconColor(RadialHudIcon __instance, ref Image ___radialImage)
	{
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		ToolHudIcon toolIcon = (ToolHudIcon)(object)((__instance is ToolHudIcon) ? __instance : null);
		if (toolIcon == null || !Object.op_Implicit((Object)(object)toolIcon.CurrentTool))
		{
			return;
		}
		InventoryToolCrestList val = Object.FindFirstObjectByType<InventoryToolCrestList>((FindObjectsInactive)1);
		if (Object.op_Implicit((Object)(object)val) && val.GetSlots().Any((InventoryToolCrestSlot slot) => (Object)(object)slot.EquippedItem == (Object)(object)toolIcon.CurrentTool))
		{
			((Graphic)___radialImage).color = UI.GetToolTypeColor(val.GetSlots().First((InventoryToolCrestSlot slot) => (Object)(object)slot.EquippedItem == (Object)(object)toolIcon.CurrentTool).Type);
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(InventoryItemToolManager), "TryPickupOrPlaceTool")]
	public static bool TryPickupOrPlaceToolPrefix(ToolItem tool, InventoryItemToolManager __instance, InventoryToolCrestList ___crestList, InventoryFloatingToolSlots ___extraSlots, ref InventoryItemSelectable ___selectedBeforePickup, ref bool __result)
	{
		//IL_012e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_0163: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0209: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_0366: Unknown result type (might be due to invalid IL or missing references)
		//IL_0424: Unknown result type (might be due to invalid IL or missing references)
		//IL_043d: Unknown result type (might be due to invalid IL or missing references)
		Traverse val = Traverse.Create((object)__instance).Property("PickedUpTool", (object[])null);
		Traverse val2 = Traverse.Create((object)__instance).Property("EquipState", (object[])null);
		val.SetValue((object)tool);
		if (!Object.op_Implicit((Object)(object)tool))
		{
			__result = false;
			return false;
		}
		IEnumerable<InventoryToolCrestSlot> enumerable = null;
		IEnumerable<InventoryToolCrestSlot> enumerable2 = null;
		IEnumerable<InventoryToolCrestSlot> enumerable3 = null;
		Action[] array = new Action[5]
		{
			delegate
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				enumerable2 = ___crestList.GetSlots();
				if (GetAvailableSlotCount(enumerable2, tool.Type, checkEmpty: true) > 0)
				{
					enumerable = enumerable2;
				}
			},
			delegate
			{
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				enumerable3 = ___extraSlots.GetSlots();
				if (GetAvailableSlotCount(enumerable3, tool.Type, checkEmpty: true) > 0)
				{
					enumerable = enumerable3;
				}
			},
			delegate
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				if (ExtraColorsGetAvailableSlotCount(enumerable2, tool.Type, checkEmpty: true) > 0)
				{
					enumerable = enumerable2;
				}
			},
			delegate
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				if (ExtraColorsGetAvailableSlotCount(enumerable3, tool.Type, checkEmpty: true) > 0)
				{
					enumerable = enumerable3;
				}
			},
			delegate
			{
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				if (ExtraColorsGetAvailableSlotCount(enumerable2, tool.Type, checkEmpty: false) > 0)
				{
					enumerable = enumerable2;
				}
				else if (ExtraColorsGetAvailableSlotCount(enumerable3, tool.Type, checkEmpty: false) > 0)
				{
					enumerable = enumerable3;
				}
			}
		};
		Action[] array2 = array;
		foreach (Action action in array2)
		{
			action();
			if (enumerable != null)
			{
				break;
			}
		}
		if (enumerable != null)
		{
			InventoryToolCrestSlot availableSlot = __instance.GetAvailableSlot(enumerable, tool.Type);
			if (Object.op_Implicit((Object)(object)availableSlot))
			{
				val2.SetValue((object)(EquipStates)1);
				___selectedBeforePickup = ((InventoryItemManager)__instance).CurrentSelected;
				if (ToolItemTypeExtensions.IsAttackType(availableSlot.Type))
				{
					if (GetAvailableSlotCount(enumerable, availableSlot.Type, checkEmpty: false) == 1)
					{
						__instance.PlaceTool(availableSlot, true);
					}
					else
					{
						((InventoryItemManager)__instance).PlayMoveSound();
						((InventoryItemManager)__instance).SetSelected((InventoryItemSelectable)(object)availableSlot, (SelectionDirection?)null, false);
					}
				}
				else if (GetAvailableSlotCount(enumerable, availableSlot.Type, checkEmpty: true) > 0)
				{
					__instance.PlaceTool(availableSlot, true);
				}
				else
				{
					int availableSlotCount = GetAvailableSlotCount(enumerable2, availableSlot.Type, checkEmpty: false);
					int availableSlotCount2 = GetAvailableSlotCount(enumerable3, availableSlot.Type, checkEmpty: false);
					if (availableSlotCount + availableSlotCount2 == 1)
					{
						__instance.PlaceTool(availableSlot, true);
					}
					else
					{
						((InventoryItemManager)__instance).PlayMoveSound();
						((InventoryItemManager)__instance).SetSelected((InventoryItemSelectable)(object)availableSlot, (SelectionDirection?)null, false);
					}
				}
				__instance.RefreshTools();
				__result = true;
				return false;
			}
			availableSlot = ExtraColorsGetAvailableSlot(enumerable, tool.Type);
			if (Object.op_Implicit((Object)(object)availableSlot))
			{
				val2.SetValue((object)(EquipStates)1);
				___selectedBeforePickup = ((InventoryItemManager)__instance).CurrentSelected;
				IEnumerable<InventoryToolCrestSlot> availableSlots = ExtraColorsGetAvailableSlots(from slot in enumerable2.Concat(enumerable3)
					where !Object.op_Implicit((Object)(object)slot.EquippedItem)
					select slot, tool.Type);
				if (availableSlots.Count() == 0)
				{
					availableSlots = ExtraColorsGetAvailableSlots(enumerable, tool.Type);
				}
				if (availableSlots.Any((InventoryToolCrestSlot slot) => ToolItemTypeExtensions.IsAttackType(slot.Type)))
				{
					if (ExtraColorsGetAvailableSlotCount(enumerable, tool.Type, checkEmpty: false) == 1)
					{
						__instance.PlaceTool(availableSlot, true);
					}
					else
					{
						((InventoryItemManager)__instance).PlayMoveSound();
						((InventoryItemManager)__instance).SetSelected((InventoryItemSelectable)(object)availableSlot, (SelectionDirection?)null, false);
					}
				}
				else if (ExtraColorsGetAvailableSlotCount(enumerable, tool.Type, checkEmpty: true) > 0)
				{
					if (availableSlots.All((InventoryToolCrestSlot slot) => slot.Type == availableSlots.First().Type))
					{
						__instance.PlaceTool(availableSlot, true);
					}
					else
					{
						((InventoryItemManager)__instance).PlayMoveSound();
						((InventoryItemManager)__instance).SetSelected((InventoryItemSelectable)(object)availableSlot, (SelectionDirection?)null, false);
					}
				}
				else
				{
					int num = ExtraColorsGetAvailableSlotCount(enumerable2, tool.Type, checkEmpty: false);
					int num2 = ExtraColorsGetAvailableSlotCount(enumerable3, tool.Type, checkEmpty: false);
					if (num + num2 == 1)
					{
						__instance.PlaceTool(availableSlot, true);
					}
					else
					{
						((InventoryItemManager)__instance).PlayMoveSound();
						((InventoryItemManager)__instance).SetSelected((InventoryItemSelectable)(object)availableSlot, (SelectionDirection?)null, false);
					}
				}
				__instance.RefreshTools();
				__result = true;
				return false;
			}
		}
		val.SetValue((object)null);
		__result = false;
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(InventoryItemToolManager), "StartSelection")]
	public static bool StartSelectionPrefix(InventoryToolCrestSlot slot, InventoryItemToolManager __instance, InventoryItemGrid ___toolList)
	{
		if (!((Object)(object)___toolList == (Object)null))
		{
			List<InventoryItemTool> listItems = ___toolList.GetListItems<InventoryItemTool>((Func<InventoryItemTool, bool>)((InventoryItemTool toolItem) => ToolCompatability(toolItem.ToolType, slot.Type)));
			List<InventoryItemTool> list = listItems.Where((InventoryItemTool toolItem) => !InventoryItemToolManager.IsToolEquipped(((InventoryItemToolBase)toolItem).ItemData)).ToList();
			InventoryItemTool val = null;
			if (list.Count > 0)
			{
				val = list[0];
			}
			else if (listItems.Count > 0)
			{
				val = listItems[0];
			}
			if (!((Object)(object)val == (Object)null))
			{
				Traverse.Create((object)__instance).Property("SelectedSlot", (object[])null).SetValue((object)slot);
				Traverse.Create((object)__instance).Property("EquipState", (object[])null).SetValue((object)(EquipStates)2);
				((InventoryItemManager)__instance).PlayMoveSound();
				((InventoryItemManager)__instance).SetSelected((InventoryItemSelectable)(object)val, (SelectionDirection?)null, false);
				__instance.RefreshTools();
			}
		}
		return false;
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(InventoryToolCrestSlot), "UpdateSlotDisplay")]
	[HarmonyPatch(typeof(InventoryItemTool), "GetNextSelectable")]
	[HarmonyPatch(typeof(InventoryItemToolManager), "PlaceTool")]
	[HarmonyPatch(typeof(InventoryItemToolManager), "RefreshTools", new Type[]
	{
		typeof(bool),
		typeof(bool)
	})]
	[HarmonyPatch(typeof(InventoryItemToolManager), "EndSelection")]
	[HarmonyPatch(typeof(InventoryToolCrestSlot), "GetNextSelectable")]
	public static IEnumerable<CodeInstruction> SlotLoadTypeTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Expected O, but got Unknown
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Expected O, but got Unknown
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Expected O, but got Unknown
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Expected O, but got Unknown
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Expected O, but got Unknown
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Expected O, but got Unknown
		CodeInstruction val = CodeInstruction.Call("InventoryToolCrestSlot:get_Type", (Type[])null, (Type[])null);
		CodeInstruction val2 = val.Clone();
		val2.opcode = OpCodes.Callvirt;
		CodeMatcher val3 = new CodeMatcher(instructions, (ILGenerator)null);
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(val, (string)null),
			new CodeMatch((OpCode?)OpCodes.Beq, (object)null, (string)null)
		}).IsValid)
		{
			val3.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brtrue);
		}
		val3.Start();
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(val2, (string)null),
			new CodeMatch((OpCode?)OpCodes.Beq, (object)null, (string)null)
		}).IsValid)
		{
			val3.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brtrue);
		}
		val3.Start();
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(val, (string)null),
			new CodeMatch((OpCode?)OpCodes.Bne_Un, (object)null, (string)null)
		}).IsValid)
		{
			val3.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brfalse);
		}
		val3.Start();
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(val2, (string)null),
			new CodeMatch((OpCode?)OpCodes.Bne_Un, (object)null, (string)null)
		}).IsValid)
		{
			val3.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brfalse);
		}
		return val3.InstructionEnumeration();
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(InventoryItemToolManager), "EndSelection")]
	public static IEnumerable<CodeInstruction> InventoryToolItemLoadTypeTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Expected O, but got Unknown
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Expected O, but got Unknown
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Expected O, but got Unknown
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Expected O, but got Unknown
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Expected O, but got Unknown
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Expected O, but got Unknown
		CodeInstruction val = CodeInstruction.Call("InventoryItemTool:get_ToolType", (Type[])null, (Type[])null);
		CodeInstruction val2 = val.Clone();
		val2.opcode = OpCodes.Callvirt;
		CodeMatcher val3 = new CodeMatcher(instructions, (ILGenerator)null);
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(val, (string)null),
			new CodeMatch((OpCode?)OpCodes.Beq, (object)null, (string)null)
		}).IsValid)
		{
			val3.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brtrue);
		}
		val3.Start();
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(val2, (string)null),
			new CodeMatch((OpCode?)OpCodes.Beq, (object)null, (string)null)
		}).IsValid)
		{
			val3.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brtrue);
		}
		val3.Start();
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(val, (string)null),
			new CodeMatch((OpCode?)OpCodes.Bne_Un, (object)null, (string)null)
		}).IsValid)
		{
			val3.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brfalse);
		}
		val3.Start();
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(val2, (string)null),
			new CodeMatch((OpCode?)OpCodes.Bne_Un, (object)null, (string)null)
		}).IsValid)
		{
			val3.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brfalse);
		}
		return val3.InstructionEnumeration();
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(InventoryItemTool), "UpdateEquippedDisplay", new Type[] { typeof(bool) })]
	public static IEnumerable<CodeInstruction> ToolItemLoadTypeTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Expected O, but got Unknown
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Expected O, but got Unknown
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Expected O, but got Unknown
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Expected O, but got Unknown
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Expected O, but got Unknown
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Expected O, but got Unknown
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Expected O, but got Unknown
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01af: Expected O, but got Unknown
		CodeInstruction val = CodeInstruction.Call("ToolItem:get_Type", (Type[])null, (Type[])null);
		CodeInstruction val2 = val.Clone();
		val2.opcode = OpCodes.Callvirt;
		CodeMatcher val3 = new CodeMatcher(instructions, (ILGenerator)null);
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(val, (string)null),
			new CodeMatch((OpCode?)OpCodes.Beq, (object)null, (string)null)
		}).IsValid)
		{
			val3.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brtrue);
		}
		val3.Start();
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(val2, (string)null),
			new CodeMatch((OpCode?)OpCodes.Beq, (object)null, (string)null)
		}).IsValid)
		{
			val3.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brtrue);
		}
		val3.Start();
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(val, (string)null),
			new CodeMatch((OpCode?)OpCodes.Bne_Un, (object)null, (string)null)
		}).IsValid)
		{
			val3.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brfalse);
		}
		val3.Start();
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(val2, (string)null),
			new CodeMatch((OpCode?)OpCodes.Bne_Un, (object)null, (string)null)
		}).IsValid)
		{
			val3.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brfalse);
		}
		return val3.InstructionEnumeration();
	}

	private static InventoryToolCrestSlot GetNextSlotOfCompatibleType(InventoryAutoNavGroup autoNavGroup, InventoryToolCrestSlot source, SelectionDirection direction, ToolItemType type)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		InventoryItemSelectable nextSelectable = autoNavGroup.GetNextSelectable<InventoryToolCrestSlot>((InventoryItemSelectable)(object)source, direction, (Func<InventoryToolCrestSlot, bool>)((InventoryToolCrestSlot slot) => ToolCompatability(slot.Type, type)));
		return (InventoryToolCrestSlot)(object)((nextSelectable is InventoryToolCrestSlot) ? nextSelectable : null);
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(InventoryItemTool), "GetNextSelectable")]
	public static void ToolGetNextSelectablePostfix(SelectionDirection direction, ref InventoryItemSelectable __result, ref InventoryItemTool __instance)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected I4, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Invalid comparison between Unknown and I4
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_0099: Unknown result type (might be due to invalid IL or missing references)
		if (!(__result is InventoryItemTool))
		{
			return;
		}
		int num = (int)direction;
		InventoryItemSelectable obj = __result;
		InventoryItemTool val = (InventoryItemTool)(object)((obj is InventoryItemTool) ? obj : null);
		object value = Traverse.Create((object)__instance).Field("manager").GetValue();
		InventoryItemToolManager val2 = (InventoryItemToolManager)((value is InventoryItemToolManager) ? value : null);
		if (!((Object)(object)val == (Object)(object)__instance) || (int)val2.EquipState != 2 || num > 1)
		{
			return;
		}
		InventoryToolCrestSlot selectedSlot = val2.SelectedSlot;
		do
		{
			if ((Object)(object)((InventoryItemSelectableDirectional)val).Selectables[num] == (Object)null)
			{
				return;
			}
			InventoryItemSelectable obj2 = ((InventoryItemSelectableDirectional)val).Selectables[num];
			val = (InventoryItemTool)(object)((obj2 is InventoryItemTool) ? obj2 : null);
		}
		while (!ToolCompatability(val.ToolType, selectedSlot.Type));
		__result = (InventoryItemSelectable)(object)val;
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(InventoryToolCrestSlot), "GetNextSelectable")]
	public static void SlotGetNextSelectablePostfix(SelectionDirection direction, ref InventoryItemSelectable __result, InventoryToolCrestSlot __instance)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Invalid comparison between Unknown and I4
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		object value = Traverse.Create((object)__instance).Field("manager").GetValue();
		InventoryItemToolManager val = (InventoryItemToolManager)((value is InventoryItemToolManager) ? value : null);
		if ((int)val.EquipState == 1 && (!((Object)(object)((InventoryItemSelectableDirectional)__instance).Selectables[direction] == (Object)(object)__result) || !((InventoryItemSelectableDirectional)__instance).FallbackSelectables[direction].Selectables.Any((InventoryItemSelectable fallback) => (Object)(object)fallback != (Object)null && ((Component)fallback).gameObject.activeInHierarchy)))
		{
			object value2 = Traverse.Create((object)__instance).Field("autoNavGroup").GetValue();
			InventoryAutoNavGroup autoNavGroup = (InventoryAutoNavGroup)((value2 is InventoryAutoNavGroup) ? value2 : null);
			object value3 = Traverse.Create((object)val).Field("selectedBeforePickup").GetValue();
			InventoryItemTool val2 = (InventoryItemTool)((value3 is InventoryItemTool) ? value3 : null);
			InventoryToolCrestSlot nextSlotOfCompatibleType = GetNextSlotOfCompatibleType(autoNavGroup, __instance, direction, val2.ToolType);
			if (Object.op_Implicit((Object)(object)nextSlotOfCompatibleType))
			{
				__result = (InventoryItemSelectable)(object)nextSlotOfCompatibleType;
			}
		}
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(InventoryItemToolManager), "ToolListHasType")]
	[HarmonyPatch(typeof(InventoryToolCrestSlot), "IsSlotInvalid")]
	public static IEnumerable<CodeInstruction> FirstArgumentToolItemTypeTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Expected O, but got Unknown
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Expected O, but got Unknown
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Expected O, but got Unknown
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Expected O, but got Unknown
		CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
		while (val.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Beq, (object)null, (string)null)
		}).IsValid)
		{
			val.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brtrue);
		}
		val.Start();
		while (val.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch((OpCode?)OpCodes.Ldarg_1, (object)null, (string)null),
			new CodeMatch((OpCode?)OpCodes.Bne_Un, (object)null, (string)null)
		}).IsValid)
		{
			val.Advance(1).InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call((LambdaExpression)m_ToolCompatability) }).SetOpcodeAndAdvance(OpCodes.Brfalse);
		}
		return val.InstructionEnumeration();
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(HeroController), "ThrowTool")]
	[HarmonyPatch(typeof(HeroController), "CanThrowTool", new Type[]
	{
		typeof(ToolItem),
		typeof(AttackToolBinding),
		typeof(bool)
	})]
	[HarmonyPatch(typeof(ToolHudIcon), "GetIsEmpty")]
	[HarmonyPatch(typeof(ToolHudIcon), "GetAmounts")]
	[HarmonyPatch(typeof(ToolHudIcon), "OnSilkSpoolRefreshed")]
	[HarmonyPatch(typeof(ToolHudIcon), "OnSilkSpoolRefreshed")]
	[HarmonyPatch(typeof(ToolItem), "HasLimitedUses")]
	public static IEnumerable<CodeInstruction> ToolGetOldTypeTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Expected O, but got Unknown
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b4: Expected O, but got Unknown
		//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f8: Expected O, but got Unknown
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014e: Expected O, but got Unknown
		CodeInstruction val = CodeInstruction.Call("ToolItem:get_Type", (Type[])null, (Type[])null);
		CodeInstruction val2 = CodeInstruction.LoadField(typeof(ToolItem), "type", false);
		CodeMatcher val3 = new CodeMatcher(instructions, (ILGenerator)null);
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch(val, (string)null)
		}).IsValid)
		{
			val3.RemoveInstruction().InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call<ToolItem, ToolItemType>(m_GetOldToolItemType) });
		}
		val3.Start();
		val.opcode = OpCodes.Callvirt;
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch(val, (string)null)
		}).IsValid)
		{
			val3.RemoveInstruction().InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call<ToolItem, ToolItemType>(m_GetOldToolItemType) });
		}
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch(val2, (string)null)
		}).IsValid)
		{
			val3.RemoveInstruction().InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call<ToolItem, ToolItemType>(m_GetOldToolItemType) });
		}
		val3.Start();
		val.opcode = OpCodes.Callvirt;
		while (val3.MatchStartForward((CodeMatch[])(object)new CodeMatch[1]
		{
			new CodeMatch(val2, (string)null)
		}).IsValid)
		{
			val3.RemoveInstruction().InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { CodeInstruction.Call<ToolItem, ToolItemType>(m_GetOldToolItemType) });
		}
		return val3.InstructionEnumeration();
	}

	[HarmonyTranspiler]
	[HarmonyPatch(typeof(InventoryItemToolManager), "OnValidate")]
	public static IEnumerable<CodeInstruction> OnValidateTranspiler(IEnumerable<CodeInstruction> instructions)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Expected O, but got Unknown
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Expected O, but got Unknown
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		CodeMatcher val = new CodeMatcher(instructions, (ILGenerator)null);
		val.MatchStartForward((CodeMatch[])(object)new CodeMatch[2]
		{
			new CodeMatch(new CodeInstruction(OpCodes.Ldarg_0, (object)null), (string)null),
			new CodeMatch(CodeInstruction.LoadField(typeof(InventoryItemToolManager), "listSectionHeaders", true), (string)null)
		});
		if (val.Pos > 0)
		{
			val.RemoveInstructions(5);
		}
		return val.InstructionEnumeration();
	}
}