Decompiled source of HornetSings v0.2.2

HornetSings.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.IO;
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.Logging;
using HarmonyLib;
using HutongGames.PlayMaker;
using HutongGames.PlayMaker.Actions;
using Microsoft.CodeAnalysis;
using Needleforge;
using Needleforge.Data;
using Silksong.FsmUtil;
using Silksong.FsmUtil.Actions;
using TeamCherry.Localization;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("HornetSings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.2.0")]
[assembly: AssemblyInformationalVersion("0.2.2+52a23e77ff9c62190b750cca5c0e3e2f0d5167f4")]
[assembly: AssemblyProduct("HornetSings")]
[assembly: AssemblyTitle("HornetSings")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/GamingInfinite/HornetSings")]
[assembly: NeutralResourcesLanguage("EN")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.2.2.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 HornetSings
{
	[BepInPlugin("io.github.gaminginfinite.hornetsings", "HornetSings", "0.2.2")]
	public class HornetSingsPlugin : BaseUnityPlugin
	{
		public static ManualLogSource logSource;

		public static AssetBundle modBundle;

		public static ToolData shermaBell;

		public static GameObject Anim;

		public FsmTemplate _trackedNeedolin;

		public static Harmony harmony;

		public const string Id = "io.github.gaminginfinite.hornetsings";

		public static string Name => "HornetSings";

		public static string Version => "0.2.2";

		private void Awake()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: 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)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			logSource = ((BaseUnityPlugin)this).Logger;
			harmony = new Harmony("voidbaroness.hornetshermasong");
			modBundle = ModHelper.LoadBundleFromAssembly("HornetSings.Resources.AssetBundles.hornetshermasing");
			Anim = modBundle.LoadAsset<GameObject>("assets/hornetshermasong/hornetshermaanim.prefab");
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + Name + " (io.github.gaminginfinite.hornetsings) has loaded!"));
			harmony.PatchAll();
			string[] allAssetNames = modBundle.GetAllAssetNames();
			for (int i = 0; i < allAssetNames.Length; i++)
			{
				ModHelper.Log(allAssetNames[i]);
			}
			Texture2D val = ModHelper.LoadTexFromAssembly("HornetSings.Resources.Images.hornetBell.png");
			Sprite val2 = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 420f);
			shermaBell = NeedleforgePlugin.AddTool("Sherma's Bell", (ToolItemType)2, new LocalisedString
			{
				Key = "ShermaBellTool",
				Sheet = "Mods.io.github.gaminginfinite.hornetsings"
			}, new LocalisedString
			{
				Key = "ShermaBellToolDesc",
				Sheet = "Mods.io.github.gaminginfinite.hornetsings"
			}, val2);
		}
	}
	internal class ModHelper
	{
		public static void Log(string msg)
		{
			HornetSingsPlugin.logSource.LogInfo((object)msg);
		}

		public static void LogError(string msg)
		{
			HornetSingsPlugin.logSource.LogError((object)msg);
		}

		public static AssetBundle? LoadBundleFromAssembly(string resourceName)
		{
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
			if (stream == null)
			{
				LogError("Couldnt load resoruce lol");
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			return AssetBundle.LoadFromMemory(array);
		}

		public static Texture2D LoadTexFromAssembly(string resourceName)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Expected O, but got Unknown
			//IL_0049: Expected O, but got Unknown
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
			if (stream == null)
			{
				LogError("Couldnt load resoruce lol");
				return null;
			}
			byte[] array = new byte[stream.Length];
			stream.Read(array, 0, array.Length);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)72, false);
			ImageConversion.LoadImage(val, array);
			return val;
		}
	}
}
namespace HornetSings.Patches
{
	[HarmonyPatch(typeof(HeroController), "Start")]
	internal class AddAnims
	{
		[HarmonyPostfix]
		public static void Postfix(HeroController __instance)
		{
			tk2dSpriteAnimator component = ((Component)__instance).GetComponent<tk2dSpriteAnimator>();
			tk2dSpriteAnimation component2 = HornetSingsPlugin.Anim.GetComponent<tk2dSpriteAnimation>();
			tk2dSpriteAnimation library = component.Library;
			tk2dSpriteAnimationClip[] clips = component.Library.clips;
			tk2dSpriteAnimationClip[] clips2 = component2.clips;
			int num = 0;
			tk2dSpriteAnimationClip[] array = (tk2dSpriteAnimationClip[])(object)new tk2dSpriteAnimationClip[clips.Length + clips2.Length];
			ReadOnlySpan<tk2dSpriteAnimationClip> readOnlySpan = new ReadOnlySpan<tk2dSpriteAnimationClip>(clips);
			readOnlySpan.CopyTo(new Span<tk2dSpriteAnimationClip>(array).Slice(num, readOnlySpan.Length));
			num += readOnlySpan.Length;
			ReadOnlySpan<tk2dSpriteAnimationClip> readOnlySpan2 = new ReadOnlySpan<tk2dSpriteAnimationClip>(clips2);
			readOnlySpan2.CopyTo(new Span<tk2dSpriteAnimationClip>(array).Slice(num, readOnlySpan2.Length));
			num += readOnlySpan2.Length;
			library.clips = array;
		}
	}
	[HarmonyPatch(typeof(PlayMakerFSM), "Start")]
	internal class PatchNeedolin
	{
		[HarmonyPostfix]
		public static void Postfix(PlayMakerFSM __instance)
		{
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Expected O, but got Unknown
			if (__instance == null || !(((Object)__instance).name == "Hero_Hornet(Clone)") || !(__instance.FsmName == "Silk Specials"))
			{
				return;
			}
			Fsm fsm = __instance.Fsm;
			RunFSM action2 = FsmUtil.GetAction<RunFSM>(fsm, "Needolin Sub", 2);
			Fsm needolinFsm = ((action2 != null) ? action2.fsmTemplateControl.RunFsm : null);
			FsmState state = needolinFsm.GetState("Start Needolin");
			FsmState startNeedolinProper = needolinFsm.GetState("Start Needolin Proper");
			FsmState needolinCancel = needolinFsm.GetState("Cancelable");
			FsmState state2 = needolinFsm.GetState("Set Silk Drain Time");
			FsmState state3 = needolinFsm.GetState("Play Needolin");
			FsmState val = FsmUtil.AddState(needolinFsm, "Sherma Bell?");
			FsmUtil.AddTransition(val, "FINISHED", startNeedolinProper.Name);
			FsmUtil.ChangeTransition(state2, "FINISHED", val.Name);
			AudioClip shermaSong = HornetSingsPlugin.modBundle.LoadAsset<AudioClip>("assets/hornetshermasong/hornet_sing.wav");
			AudioClip defaultHornetNeedolin = (AudioClip)FsmUtil.GetAction<StartNeedolinAudioLoop>(startNeedolinProper, 6).DefaultClip.Value;
			FsmBool atBench = needolinFsm.GetFsmBool("At Bench");
			new DelegateAction<Action>().Method = delegate(Action action)
			{
				if (HornetSingsPlugin.shermaBell.IsEquipped)
				{
					FsmUtil.GetAction<Tk2dPlayAnimationWithEvents>(needolinCancel, 2).clipName = FsmString.op_Implicit("");
				}
				action();
			};
			DelegateAction<Action> val2 = new DelegateAction<Action>
			{
				Method = delegate(Action action)
				{
					bool isEquipped2 = HornetSingsPlugin.shermaBell.IsEquipped;
					FsmString fsmString2 = needolinFsm.GetFsmString("Play Clip");
					if (atBench.Value)
					{
						fsmString2.Value = "NeedolinSit Start";
					}
					else if (isEquipped2)
					{
						fsmString2.Value = "hornetShermaSingStart";
					}
					else
					{
						fsmString2.Value = "Needolin Start";
					}
					action();
				}
			};
			val2.Arg = ((FsmStateAction)val2).Finish;
			DelegateAction<Action> val3 = new DelegateAction<Action>
			{
				Method = delegate(Action action)
				{
					bool isEquipped = HornetSingsPlugin.shermaBell.IsEquipped;
					FsmString fsmString = needolinFsm.GetFsmString("Play Clip");
					if (atBench.Value)
					{
						fsmString.Value = "NeedolinSit Play";
					}
					else if (isEquipped)
					{
						fsmString.Value = "hornetShermaSing";
					}
					else
					{
						fsmString.Value = "Needolin Play";
					}
					action();
				}
			};
			val3.Arg = ((FsmStateAction)val3).Finish;
			FsmUtil.ReplaceAction(state, (FsmStateAction)(object)val2, 6);
			FsmUtil.ReplaceAction(state3, (FsmStateAction)(object)val3, 4);
			FsmUtil.AddLambdaMethod(val, (Action<Action>)delegate(Action action)
			{
				if (HornetSingsPlugin.shermaBell.IsEquipped)
				{
					FsmUtil.GetAction<StartNeedolinAudioLoop>(startNeedolinProper, 6).DefaultClip.Value = (Object)(object)shermaSong;
				}
				else
				{
					FsmUtil.GetAction<StartNeedolinAudioLoop>(startNeedolinProper, 6).DefaultClip.Value = (Object)(object)defaultHornetNeedolin;
				}
				action();
			});
		}
	}
}