Decompiled source of NeedleArts v0.3.0

NeedleArts.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using HutongGames.PlayMaker;
using HutongGames.PlayMaker.Actions;
using InControl;
using Microsoft.CodeAnalysis;
using NeedleArts.ArtTools;
using NeedleArts.Managers;
using NeedleArts.Utils;
using Needleforge;
using Needleforge.Data;
using Needleforge.Makers;
using Silksong.FsmUtil;
using Silksong.FsmUtil.Actions;
using TeamCherry.Localization;
using TeamCherry.NestedFadeGroup;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("NeedleArts")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0+66b980173fbcef1978a77ed8e7b8c6e8b72d17a1")]
[assembly: AssemblyProduct("NeedleArts")]
[assembly: AssemblyTitle("NeedleArts")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/jadedbay/NeedleArts")]
[assembly: NeutralResourcesLanguage("EN")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.0.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace NeedleArts
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("io.github.jadedbay.needlearts", "NeedleArts", "0.3.0")]
	public class NeedleArtsPlugin : BaseUnityPlugin
	{
		private Harmony harmony = new Harmony("io.github.jadedbay.needlearts");

		internal static ManualLogSource Log;

		public static readonly ColorData NeedleArtsToolType = NeedleforgePlugin.AddToolColor("NeedleArts", new Color(0.966f, 0.6f, 0.29f), true);

		public static ConfigEntry<bool> UnlockNeedleArts;

		public const string Id = "io.github.jadedbay.needlearts";

		public NeedleArtManager NeedleArtManager { get; private set; }

		public static string Name => "NeedleArts";

		public static string Version => "0.3.0";

		private void Awake()
		{
			NeedleArtManager = new NeedleArtManager();
			NeedleArts.Managers.NeedleArtManager.Instance = NeedleArtManager;
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + Name + " (io.github.jadedbay.needlearts) has loaded!"));
			harmony.PatchAll();
			InitializeConfig();
			InitializeNeedleArtTools();
		}

		private void OnDestroy()
		{
			NeedleArts.Managers.NeedleArtManager.Instance = null;
		}

		private static void InitializeNeedleArtTools()
		{
			NeedleArtManager instance = NeedleArts.Managers.NeedleArtManager.Instance;
			instance.AddNeedleArt(new CrestArt("HunterArt", "FINISHED", "Antic", "Hunter_Anim", 0, null));
			instance.AddNeedleArt(new CrestArt("ReaperArt", "REAPER", "Antic Rpr", "Reaper_Anim", 2, "completedMemory_reaper"));
			instance.AddNeedleArt(new CrestArt("WandererArt", "WANDERER", "Wanderer Antic", "Wanderer_Anim", 4, "completedMemory_wanderer"));
			instance.AddNeedleArt(new CrestArt("BeastArt", "WARRIOR", "Warrior Antic", "Warrior_Anim", 3, "completedMemory_beast"));
			instance.AddNeedleArt(new CrestArt("WitchArt", "WITCH", "Antic", "Whip_Anim", 6, "completedMemory_witch"));
			instance.AddNeedleArt(new CrestArt("ArchitectArt", "TOOLMASTER", "Antic Drill", "Toolmaster_Anim", 5, "completedMemory_toolmaster"));
			instance.AddNeedleArt(new CrestArt("ShamanArt", "SHAMAN", "Antic", "Shaman_Anim", 7, "completedMemory_shaman"));
		}

		public static ToolItemType ToolType()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			return NeedleArtsToolType.Type;
		}

		private void InitializeConfig()
		{
			UnlockNeedleArts = ((BaseUnityPlugin)this).Config.Bind<bool>("Cheats/Testing", "Unlock Needle Arts", false, "Instantly unlock Needle Strike and all Needle Arts.");
			UnlockNeedleArts.SettingChanged += delegate
			{
				if (UnlockNeedleArts.Value)
				{
					PlayerData instance = PlayerData.instance;
					if (instance != null)
					{
						instance.hasChargeSlash = true;
						foreach (NeedleArt allNeedleArt in NeedleArtManager.GetAllNeedleArts())
						{
							allNeedleArt.ToolItem.Unlock((Action)null, (PopupFlags)3);
						}
					}
					UnlockNeedleArts.Value = false;
				}
			};
		}
	}
}
namespace NeedleArts.Utils
{
	public static class CrestArtUtil
	{
		private static readonly Dictionary<string, string> CrestToArt = new Dictionary<string, string>
		{
			{ "Hunter", "HunterArt" },
			{ "Reaper", "ReaperArt" },
			{ "Wanderer", "WandererArt" },
			{ "Warrior", "BeastArt" },
			{ "Witch", "WitchArt" },
			{ "Toolmaster", "ArchitectArt" },
			{ "Spell", "ShamanArt" }
		};

		private static readonly Dictionary<string, string> ArtToCrest = CrestToArt.ToDictionary<KeyValuePair<string, string>, string, string>((KeyValuePair<string, string> kvp) => kvp.Value, (KeyValuePair<string, string> kvp) => kvp.Key);

		public static string GetArtName(string crestName)
		{
			crestName = (crestName.Contains("Hunter") ? "Hunter" : crestName);
			string value;
			return CrestToArt.TryGetValue(crestName, out value) ? value : null;
		}

		public static NeedleArt GetCrestArt()
		{
			return NeedleArtManager.Instance.GetNeedleArtByName(GetArtName(PlayerData.instance.CurrentCrestID));
		}
	}
	public static class Util
	{
		public static Texture2D LoadTextureFromAssembly(string resourceName)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			using Stream stream = executingAssembly.GetManifestResourceStream(resourceName);
			if (stream == null)
			{
				NeedleArtsPlugin.Log.LogError((object)("Resource not found: " + resourceName));
				return null;
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			byte[] array = memoryStream.ToArray();
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, array);
			return val;
		}

		public static tk2dSpriteAnimationClip CopyClip(tk2dSpriteAnimationClip clip, string newName)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			return new tk2dSpriteAnimationClip
			{
				name = newName,
				frames = clip.frames,
				fps = clip.fps,
				loopStart = clip.loopStart,
				wrapMode = clip.wrapMode
			};
		}
	}
}
namespace NeedleArts.Patches
{
	[HarmonyPatch]
	public class AddSlot
	{
		private const float SlotPosX = -0.5f;

		private const float SlotPosY = -3.85f;

		private const float SlotXGap = 1f;

		private static List<NeedleArtSlot> slots;

		[HarmonyPatch(typeof(InventoryFloatingToolSlots), "Awake")]
		[HarmonyPostfix]
		private static void SpawnSlot(InventoryFloatingToolSlots __instance)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: 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_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Expected O, but got Unknown
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Expected O, but got Unknown
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Expected O, but got Unknown
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			slots = new List<NeedleArtSlot>(3)
			{
				new NeedleArtSlot(__instance, (AttackToolBinding)1),
				new NeedleArtSlot(__instance, (AttackToolBinding)0),
				new NeedleArtSlot(__instance, (AttackToolBinding)2)
			};
			Test val = default(Test);
			val.FieldName = "hasChargeSlash";
			val.Type = (TestType)0;
			val.BoolValue = true;
			Test val2 = val;
			List<Config> list = new List<Config>();
			Config[] configs = __instance.configs;
			PlayerDataTest val4;
			foreach (Config val3 in configs)
			{
				val4 = new PlayerDataTest();
				PlayerDataTest obj = val4;
				TestGroup[] array = new TestGroup[1];
				TestGroup val5 = default(TestGroup);
				Test[] tests = val3.Condition.TestGroups[0].Tests;
				int num = 0;
				Test[] array2 = (Test[])(object)new Test[1 + tests.Length];
				ReadOnlySpan<Test> readOnlySpan = new ReadOnlySpan<Test>(tests);
				readOnlySpan.CopyTo(new Span<Test>(array2).Slice(num, readOnlySpan.Length));
				num += readOnlySpan.Length;
				array2[num] = val2;
				num++;
				val5.Tests = array2;
				array[0] = val5;
				obj.TestGroups = (TestGroup[])(object)array;
				PlayerDataTest condition = val4;
				Config val6 = new Config();
				List<Slot> list2 = new List<Slot>();
				list2.AddRange(val3.Slots);
				list2.AddRange(slots.Select((NeedleArtSlot s) => s.slot));
				val6.Slots = list2.ToArray();
				val6.Brackets = new ReadOnlySpan<GameObject>(val3.Brackets).ToArray();
				val6.PositionOffset = val3.PositionOffset;
				val6.Condition = condition;
				list.Add(val6);
			}
			Config val7 = new Config();
			Config obj2 = val7;
			List<Slot> list3 = new List<Slot>();
			list3.AddRange(slots.Select((NeedleArtSlot s) => s.slot));
			obj2.Slots = list3.ToArray();
			val7.Brackets = Array.Empty<GameObject>();
			val7.PositionOffset = new Vector2(0f, 0f);
			Config obj3 = val7;
			val4 = new PlayerDataTest();
			val4.TestGroups = (TestGroup[])(object)new TestGroup[1]
			{
				new TestGroup
				{
					Tests = (Test[])(object)new Test[1] { val2 }
				}
			};
			obj3.Condition = val4;
			Config val8 = val7;
			Config val9 = val8;
			Config[] configs2 = __instance.configs;
			List<Config> list4 = list;
			int num2 = 0;
			Config[] array3 = (Config[])(object)new Config[1 + (configs2.Length + list4.Count)];
			array3[num2] = val9;
			num2++;
			ReadOnlySpan<Config> readOnlySpan2 = new ReadOnlySpan<Config>(configs2);
			readOnlySpan2.CopyTo(new Span<Config>(array3).Slice(num2, readOnlySpan2.Length));
			num2 += readOnlySpan2.Length;
			foreach (Config item in list4)
			{
				array3[num2] = item;
				num2++;
			}
			__instance.configs = array3;
		}

		[HarmonyPatch(typeof(InventoryFloatingToolSlots), "Evaluate")]
		[HarmonyPostfix]
		private static void SetSlotValues(InventoryFloatingToolSlots __instance)
		{
			if (Extensions.IsNullOrEmpty<NeedleArtSlot>((ICollection<NeedleArtSlot>)slots) || (Object)(object)slots[0].gameObject == (Object)null)
			{
				return;
			}
			List<GameObject> list = (from go in Resources.FindObjectsOfTypeAll<GameObject>()
				where ((Object)go).name == "Attack Slot(Clone)" && ((Object)go.transform.parent).name == "Hunter"
				select go).ToList();
			list.Add(((Component)((Component)__instance).transform.Find("Defend Slot")).gameObject);
			foreach (NeedleArtSlot slot in slots)
			{
				slot.Evaluate(list);
			}
		}

		[HarmonyPatch(typeof(InventoryItemGrid), "PositionGridItems")]
		[HarmonyPostfix]
		private static void SetNeedleArtSlotPositions(InventoryItemGrid __instance, List<InventoryItemSelectableDirectional> childItems)
		{
			if (((Object)((Component)__instance).gameObject).name != "Floating Slots")
			{
				return;
			}
			PlayerData instance = PlayerData.instance;
			float num = ((instance.UnlockedExtraYellowSlot && !instance.UnlockedExtraBlueSlot) ? 1.73f : 0f);
			int num2 = 0;
			foreach (InventoryItemSelectableDirectional item in childItems.Where((InventoryItemSelectableDirectional slot) => ((Object)slot).name == "NeedleArt Slot"))
			{
				Extensions.SetLocalPosition2D(((Component)item).transform, -0.5f + 1f * (float)num2, -3.85f + num);
				num2++;
			}
		}

		[HarmonyPatch(typeof(InventoryItemGrid), "LinkGridSelectables")]
		[HarmonyPostfix]
		private static void FixNav(InventoryItemGrid __instance, List<InventoryItemSelectableDirectional> childItems)
		{
			if (((Object)((Component)__instance).gameObject).name != "Floating Slots")
			{
				return;
			}
			List<InventoryItemSelectableDirectional> list = childItems.Where((InventoryItemSelectableDirectional slot) => ((Object)slot).name == "NeedleArt Slot").ToList();
			if (list.Count != 0)
			{
				InventoryItemSelectable val = list[0].Selectables[0];
				for (int i = 0; i < list.Count; i++)
				{
					InventoryItemSelectableDirectional val2 = list[i];
					val2.Selectables[0] = val;
					val2.Selectables[1] = null;
					val2.Selectables[2] = (InventoryItemSelectable)(object)((i > 0) ? list[i - 1] : null);
					val2.Selectables[3] = (InventoryItemSelectable)(object)((i < list.Count - 1) ? list[i + 1] : null);
				}
			}
		}

		[HarmonyPatch(typeof(InventoryItemSelectableDirectional), "GetNextSelectable", new Type[]
		{
			typeof(SelectionDirection),
			typeof(bool)
		})]
		[HarmonyPrefix]
		private static void UseParentNav(InventoryItemSelectableDirectional __instance, SelectionDirection direction, ref bool allowAutoNavOnFirst)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (!(((Object)__instance).name != "NeedleArt Slot") && !((Object)(object)__instance.Selectables[direction] != (Object)null))
			{
				allowAutoNavOnFirst = false;
			}
		}
	}
	internal class NeedleArtSlot
	{
		public GameObject gameObject;

		public Slot slot;

		public AttackToolBinding binding;

		public NeedleArtSlot(InventoryFloatingToolSlots inventoryFloatingToolSlots, AttackToolBinding binding)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			this.binding = binding;
			gameObject = Object.Instantiate<GameObject>(((Component)((Component)inventoryFloatingToolSlots).transform.Find("Defend Slot")).gameObject, ((Component)inventoryFloatingToolSlots).transform);
			((Object)gameObject).name = "NeedleArt Slot";
			gameObject.SetActive(false);
			gameObject.transform.localScale = new Vector3(0.6f, 0.6f);
			slot = new Slot
			{
				SlotObject = gameObject.GetComponent<InventoryToolCrestSlot>(),
				Type = NeedleArtsPlugin.ToolType(),
				Id = "NeedleArtsSlot_" + ((object)(AttackToolBinding)(ref binding)).ToString(),
				CursedSlot = Object.Instantiate<GameObject>(((Component)((Component)inventoryFloatingToolSlots).transform.Find("Cursed Socket Top")).gameObject, ((Component)inventoryFloatingToolSlots).transform)
			};
		}

		public void Evaluate(List<GameObject> attackSlots)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			gameObject.GetComponent<InventoryToolCrestSlot>().slotInfo.AttackBinding = binding;
			GameObject val = attackSlots.First((GameObject s) => s.GetComponent<InventoryToolCrestSlot>().slotInfo.AttackBinding == binding);
			((Component)gameObject.transform.Find("Background Group/Background")).GetComponent<Animator>().runtimeAnimatorController = ((Component)val.transform.Find("Background Group/Background")).GetComponent<Animator>().runtimeAnimatorController;
		}
	}
	[HarmonyPatch]
	public class AutoEquip
	{
		[HarmonyPatch(typeof(PlayMakerFSM), "Awake")]
		[HarmonyPostfix]
		private static void EquipAtPinstress(PlayMakerFSM __instance)
		{
			if (__instance != null && ((Object)__instance).name == "Pinstress Interior Ground Sit" && __instance.FsmName == "Behaviour")
			{
				FsmUtil.InsertAction(FsmUtil.GetState(__instance, "Save"), 4, (FsmStateAction)(object)new DelegateAction<object>
				{
					Arg = new object(),
					Method = delegate
					{
						NeedleArtManager.AutoEquipArt(CrestArtUtil.GetCrestArt().ToolItem);
					}
				});
			}
		}
	}
	[HarmonyPatch]
	internal class ChangeHeader
	{
		[HarmonyPatch(typeof(InventoryItemToolManager), "Awake")]
		[HarmonyPostfix]
		private static void ChangeHeaderSprite(InventoryItemToolManager __instance)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			NestedFadeGroupSpriteRenderer val = __instance.listSectionHeaders[NeedleArtsPlugin.ToolType()];
			Texture2D val2 = Util.LoadTextureFromAssembly("NeedleArts.Resources.NeedleArtUIHeading.png");
			Sprite sprite = Sprite.Create(val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), new Vector2(0.5f, 0.5f), 64f);
			val.Sprite = sprite;
		}
	}
	[HarmonyPatch]
	internal class CopyAnims
	{
		private static bool _hasAddedAnims;

		[HarmonyPatch(typeof(HeroController), "Awake")]
		[HarmonyPostfix]
		private static void CopyAnimations(HeroController __instance)
		{
			if (_hasAddedAnims)
			{
				return;
			}
			List<tk2dSpriteAnimationClip> list = new List<tk2dSpriteAnimationClip>();
			tk2dSpriteAnimator animator = __instance.AnimCtrl.animator;
			list.Add(Util.CopyClip(((IEnumerable<tk2dSpriteAnimationClip>)animator.Library.clips).FirstOrDefault((Func<tk2dSpriteAnimationClip, bool>)((tk2dSpriteAnimationClip c) => c.name == "Slash_Charged")), "Hunter_Anim"));
			ConfigGroup[] configs = __instance.configs;
			foreach (ConfigGroup val in configs)
			{
				if ((Object)(object)val.Config.heroAnimOverrideLib == (Object)null)
				{
					continue;
				}
				tk2dSpriteAnimationClip val2 = ((IEnumerable<tk2dSpriteAnimationClip>)val.Config.heroAnimOverrideLib.clips).FirstOrDefault((Func<tk2dSpriteAnimationClip, bool>)((tk2dSpriteAnimationClip c) => c.name == "Slash_Charged"));
				if (val2 != null)
				{
					list.Add(Util.CopyClip(val2, ((Object)val.Config).name + "_Anim"));
					tk2dSpriteAnimationClip val3 = ((IEnumerable<tk2dSpriteAnimationClip>)val.Config.heroAnimOverrideLib.clips).FirstOrDefault((Func<tk2dSpriteAnimationClip, bool>)((tk2dSpriteAnimationClip c) => c.name == "NeedleArt Dash"));
					if (val3 != null)
					{
						list.Add(Util.CopyClip(val3, "NeedleArt Dash"));
					}
					tk2dSpriteAnimationClip val4 = ((IEnumerable<tk2dSpriteAnimationClip>)val.Config.heroAnimOverrideLib.clips).FirstOrDefault((Func<tk2dSpriteAnimationClip, bool>)((tk2dSpriteAnimationClip c) => c.name == "Slash_Charged_Loop"));
					if (val4 != null)
					{
						list.Add(Util.CopyClip(val4, "Slash_Charged_Loop"));
					}
				}
			}
			tk2dSpriteAnimation library = animator.Library;
			tk2dSpriteAnimationClip[] clips = animator.Library.clips;
			List<tk2dSpriteAnimationClip> list2 = list;
			int num = 0;
			tk2dSpriteAnimationClip[] array = (tk2dSpriteAnimationClip[])(object)new tk2dSpriteAnimationClip[clips.Length + list2.Count];
			ReadOnlySpan<tk2dSpriteAnimationClip> readOnlySpan = new ReadOnlySpan<tk2dSpriteAnimationClip>(clips);
			readOnlySpan.CopyTo(new Span<tk2dSpriteAnimationClip>(array).Slice(num, readOnlySpan.Length));
			num += readOnlySpan.Length;
			foreach (tk2dSpriteAnimationClip item in list2)
			{
				array[num] = item;
				num++;
			}
			library.clips = array;
			ConfigGroup[] configs2 = __instance.configs;
			foreach (ConfigGroup val5 in configs2)
			{
				if ((Object)(object)val5.Config.heroAnimOverrideLib == (Object)null)
				{
					continue;
				}
				tk2dSpriteAnimation heroAnimOverrideLib = val5.Config.heroAnimOverrideLib;
				tk2dSpriteAnimationClip[] clips2 = val5.Config.heroAnimOverrideLib.clips;
				List<tk2dSpriteAnimationClip> list3 = list;
				int num2 = 0;
				tk2dSpriteAnimationClip[] array2 = (tk2dSpriteAnimationClip[])(object)new tk2dSpriteAnimationClip[clips2.Length + list3.Count];
				ReadOnlySpan<tk2dSpriteAnimationClip> readOnlySpan2 = new ReadOnlySpan<tk2dSpriteAnimationClip>(clips2);
				readOnlySpan2.CopyTo(new Span<tk2dSpriteAnimationClip>(array2).Slice(num2, readOnlySpan2.Length));
				num2 += readOnlySpan2.Length;
				foreach (tk2dSpriteAnimationClip item2 in list3)
				{
					array2[num2] = item2;
					num2++;
				}
				heroAnimOverrideLib.clips = array2;
			}
			_hasAddedAnims = true;
		}
	}
	[HarmonyPatch]
	internal class PatchChargedSlash
	{
		[HarmonyPatch(typeof(HeroController), "CanNailCharge")]
		[HarmonyPrefix]
		private static bool IsNeedleArtEquipped()
		{
			return NeedleArtManager.Instance.GetAllNeedleArts().Any((NeedleArt tool) => ((ToolBase)tool.ToolItem).IsEquipped);
		}

		[HarmonyPatch(typeof(GetHeroAttackObject), "GetGameObject")]
		[HarmonyPostfix]
		private static void PatchGetGameObject(GetHeroAttackObject __instance, ref GameObject __result)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Invalid comparison between Unknown and I4
			if ((int)(AttackObjects)(object)__instance.Attack.Value == 7)
			{
				NeedleArt activeNeedleArt = NeedleArtManager.Instance.GetActiveNeedleArt();
				if (activeNeedleArt != null)
				{
					__result = activeNeedleArt.GetChargeSlash();
				}
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void PatchChargeSlashRecoils(ref bool __result)
		{
			NeedleArt activeNeedleArt = NeedleArtManager.Instance.GetActiveNeedleArt();
			if (activeNeedleArt != null)
			{
				__result = activeNeedleArt.GetConfig().chargeSlashRecoils;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void PatchChargeSlashChain(ref int __result)
		{
			NeedleArt activeNeedleArt = NeedleArtManager.Instance.GetActiveNeedleArt();
			if (activeNeedleArt != null)
			{
				__result = activeNeedleArt.GetConfig().chargeSlashChain;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void PatchChargeSlashLungeSpeed(ref float __result)
		{
			NeedleArt activeNeedleArt = NeedleArtManager.Instance.GetActiveNeedleArt();
			if (activeNeedleArt != null)
			{
				__result = activeNeedleArt.GetConfig().chargeSlashLungeSpeed;
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void PatchChargeSlashLungeDeceleration(ref float __result)
		{
			NeedleArt activeNeedleArt = NeedleArtManager.Instance.GetActiveNeedleArt();
			if (activeNeedleArt != null)
			{
				__result = activeNeedleArt.GetConfig().chargeSlashLungeDeceleration;
			}
		}

		[HarmonyPatch(typeof(PlayMakerFSM), "Start")]
		[HarmonyPostfix]
		private static void PatchNailArtsFSM(PlayMakerFSM __instance)
		{
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			if (__instance == null || !(((Object)__instance).name == "Hero_Hornet(Clone)") || !(__instance.FsmName == "Nail Arts"))
			{
				return;
			}
			FsmUtil.AddStringVariable(__instance, "NeedleArtName");
			FsmUtil.AddStringVariable(__instance, "ClipName");
			FsmState state = FsmUtil.GetState(__instance, "Get Charge Slash");
			FsmUtil.InsertAction(state, 0, (FsmStateAction)(object)new DelegateAction<(NamedVariable, NamedVariable, NeedleArtManager)>
			{
				Arg = ((NamedVariable)(object)FsmUtil.GetStringVariable(__instance, "NeedleArtName"), (NamedVariable)(object)FsmUtil.GetStringVariable(__instance, "ClipName"), NeedleArtManager.Instance),
				Method = delegate((NamedVariable needleArtName, NamedVariable clipName, NeedleArtManager manager) args)
				{
					args.manager.SetActiveNeedleArt();
					NeedleArt activeNeedleArt = args.manager.GetActiveNeedleArt();
					args.needleArtName.RawValue = activeNeedleArt.Name;
					args.clipName.RawValue = activeNeedleArt.AnimName;
				}
			});
			FsmUtil.RemoveActionsOfType<CheckIfCrestEquipped>(FsmUtil.GetState(__instance, "Antic Type"));
			foreach (NeedleArt allNeedleArt in NeedleArtManager.Instance.GetAllNeedleArts())
			{
				allNeedleArt.EditFsm(__instance);
			}
			FsmUtil.ReplaceAction(FsmUtil.GetState(__instance, "Slash Recoil?"), 0, (FsmStateAction)new StringCompare
			{
				stringVariable = FsmUtil.GetStringVariable(__instance, "NeedleArtName"),
				compareTo = FsmString.op_Implicit("ShamanArt"),
				notEqualEvent = FsmEvent.Finished
			});
			FsmUtil.AddAction(FsmUtil.GetState(__instance, "Regain Full Control"), (FsmStateAction)(object)new DelegateAction<NeedleArtManager>
			{
				Arg = NeedleArtManager.Instance,
				Method = delegate(NeedleArtManager manager)
				{
					manager.ResetActiveNeedleArt();
				}
			});
		}
	}
	[HarmonyPatch]
	internal class PatchToolMaker
	{
		[HarmonyPatch(typeof(ToolMaker), "AddCustomTool", new Type[] { typeof(ToolItem) })]
		[HarmonyPostfix]
		private static void AddToolItem(ToolItem toolItem)
		{
			NeedleArt needleArtByName = NeedleArtManager.Instance.GetNeedleArtByName(toolItem.name);
			needleArtByName.ToolItem = toolItem;
			(needleArtByName as CrestArt)?.AddUnlockTest();
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPostfix]
		private static void RemovePercentage(ToolItem __instance, ref bool __result)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.Type == NeedleArtsPlugin.ToolType())
			{
				__result = false;
			}
		}
	}
}
namespace NeedleArts.Managers
{
	public class NeedleArtManager
	{
		private readonly List<NeedleArt> NeedleArts = new List<NeedleArt>();

		private NeedleArt? _activeNeedleArt;

		private bool autoEquip;

		public static NeedleArtManager Instance { get; internal set; }

		public void AddNeedleArt(NeedleArt needleArt)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			NeedleArts.Add(needleArt);
			Texture2D val = Util.LoadTextureFromAssembly("NeedleArts.Resources." + needleArt.Name + "Icon.png");
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 260f);
			ToolData val3 = NeedleforgePlugin.AddTool(needleArt.Name, NeedleArtsPlugin.ToolType(), new LocalisedString
			{
				Key = needleArt.Name + "_Tool",
				Sheet = "Mods.io.github.jadedbay.needlearts"
			}, new LocalisedString
			{
				Key = needleArt.Name + "_ToolDesc",
				Sheet = "Mods.io.github.jadedbay.needlearts"
			}, val2);
			val3.UnlockedAtStart = false;
		}

		public List<NeedleArt> GetAllNeedleArts()
		{
			return NeedleArts;
		}

		public NeedleArt? GetNeedleArtByName(string name)
		{
			string name2 = name;
			return NeedleArts.FirstOrDefault((NeedleArt art) => art.Name == name2);
		}

		public void SetActiveNeedleArt()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			InputHandler inputHandler = HeroController.instance.inputHandler;
			PlayerData instance = PlayerData.instance;
			List<(SlotData, AttackToolBinding)> source = new List<(SlotData, AttackToolBinding)>(3)
			{
				(((SerializableNamedList<SlotData, NamedData>)(object)instance.ExtraToolEquips).GetData("NeedleArtsSlot_Up"), (AttackToolBinding)1),
				(((SerializableNamedList<SlotData, NamedData>)(object)instance.ExtraToolEquips).GetData("NeedleArtsSlot_Neutral"), (AttackToolBinding)0),
				(((SerializableNamedList<SlotData, NamedData>)(object)instance.ExtraToolEquips).GetData("NeedleArtsSlot_Down"), (AttackToolBinding)2)
			};
			_activeNeedleArt = (from s in source
				where ((int)s.binding == 1 && ((OneAxisInputControl)inputHandler.inputActions.Up).IsPressed) || ((int)s.binding == 2 && ((OneAxisInputControl)inputHandler.inputActions.Down).IsPressed)
				select GetNeedleArtByName(s.data.EquippedTool)).FirstOrDefault((NeedleArt art) => art != null) ?? GetNeedleArtByName(source.Single<(SlotData, AttackToolBinding)>(((SlotData data, AttackToolBinding binding) s) => (int)s.binding == 0).Item1.EquippedTool) ?? source.Select<(SlotData, AttackToolBinding), NeedleArt>(((SlotData data, AttackToolBinding binding) slot) => GetNeedleArtByName(slot.data.EquippedTool)).FirstOrDefault((NeedleArt art) => art != null);
		}

		public NeedleArt? GetActiveNeedleArt()
		{
			return _activeNeedleArt;
		}

		public void ResetActiveNeedleArt()
		{
			_activeNeedleArt = null;
		}

		public static void AutoEquipArt(ToolItem toolItem)
		{
			ToolItemManager.SetExtraEquippedTool("NeedleArtsSlot_Neutral", toolItem);
		}
	}
}
namespace NeedleArts.ArtTools
{
	public class CrestArt : NeedleArt
	{
		private string EventName { get; }

		private int ConfigId { get; }

		private string AnticName { get; }

		private string? CrestDataField { get; }

		public CrestArt(string name, string eventName, string anticName, string animName, int configId, string? crestDataField)
		{
			EventName = eventName;
			ConfigId = configId;
			AnticName = anticName;
			CrestDataField = crestDataField;
			base..ctor(name, animName);
		}

		public override GameObject GetChargeSlash()
		{
			return HeroController.instance.configs[ConfigId].ChargeSlash;
		}

		public override HeroControllerConfig GetConfig()
		{
			return HeroController.instance.configs[ConfigId].Config;
		}

		public override void EditFsm(PlayMakerFSM fsm)
		{
			//IL_000c: 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)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			FsmUtil.AddAction(FsmUtil.GetState(fsm, "Antic Type"), (FsmStateAction)new StringCompare
			{
				stringVariable = FsmUtil.GetStringVariable(fsm, "NeedleArtName"),
				compareTo = FsmString.op_Implicit(base.Name),
				equalEvent = FsmEvent.GetFsmEvent(EventName)
			});
			FsmUtil.GetFirstActionOfType<Tk2dPlayAnimationWithEvents>(FsmUtil.GetState(fsm, AnticName)).clipName = FsmUtil.GetStringVariable(fsm, "ClipName");
		}

		public void AddUnlockTest()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: 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)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Expected O, but got Unknown
			TestGroup[] testGroups = base.ToolItem.alternateUnlockedTest.TestGroups;
			int num = 0;
			TestGroup[] array = (TestGroup[])(object)new TestGroup[1 + testGroups.Length];
			ReadOnlySpan<TestGroup> readOnlySpan = new ReadOnlySpan<TestGroup>(testGroups);
			readOnlySpan.CopyTo(new Span<TestGroup>(array).Slice(num, readOnlySpan.Length));
			num += readOnlySpan.Length;
			int num2 = num;
			TestGroup val = default(TestGroup);
			Test[] array2 = (Test[])((CrestDataField == null) ? ((Array)Array.Empty<Test>()) : ((Array)new Test[1]
			{
				new Test
				{
					Type = (TestType)0,
					FieldName = CrestDataField,
					BoolValue = true
				}
			}));
			int num3 = 0;
			Test[] array3 = (Test[])(object)new Test[1 + array2.Length];
			ReadOnlySpan<Test> readOnlySpan2 = new ReadOnlySpan<Test>(array2);
			readOnlySpan2.CopyTo(new Span<Test>(array3).Slice(num3, readOnlySpan2.Length));
			num3 += readOnlySpan2.Length;
			array3[num3] = new Test
			{
				Type = (TestType)0,
				FieldName = "hasChargeSlash",
				BoolValue = true
			};
			num3++;
			val.Tests = array3;
			array[num2] = val;
			num++;
			TestGroup[] testGroups2 = array;
			base.ToolItem.alternateUnlockedTest = new PlayerDataTest
			{
				TestGroups = testGroups2
			};
		}
	}
	public abstract class NeedleArt
	{
		public string Name { get; }

		public ToolItem ToolItem { get; set; }

		public string AnimName { get; }

		protected NeedleArt(string name, string animName)
		{
			Name = name;
			AnimName = animName;
			base..ctor();
		}

		public abstract GameObject GetChargeSlash();

		public abstract HeroControllerConfig GetConfig();

		public abstract void EditFsm(PlayMakerFSM fsm);
	}
}