Decompiled source of FalseSonLaserCancel v1.1.1

FalseSonLaserCancel.dll

Decompiled a week ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using EntityStates;
using HarmonyLib;
using RoR2;
using UnityEngine;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace FalseSonLaserCancel;

[BepInPlugin("binma.falseson.lasercancel", "False Son Laser Cancel", "1.1.1")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Expected O, but got Unknown
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f4: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Harmony val = new Harmony("binma.falseson.lasercancel");
		val.Patch((MethodBase)AccessTools.Method(typeof(GenericSkill), "ExecuteIfReady", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin), "PrimaryPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		string[] array = new string[3] { "EntityStates.FalseSon.ClubSwing", "EntityStates.FalseSon.OverheadClubSwing", "EntityStates.FalseSon.ClubSwing3" };
		foreach (string text in array)
		{
			Type type = AccessTools.TypeByName(text);
			MethodInfo methodInfo = ((!(type != null)) ? null : AccessTools.DeclaredMethod(type, "GetMinimumInterruptPriority", (Type[])null, (Type[])null));
			if (methodInfo == null && type != null)
			{
				methodInfo = AccessTools.Method(type, "GetMinimumInterruptPriority", (Type[])null, (Type[])null);
			}
			if (methodInfo != null)
			{
				MethodInfo methodInfo2 = methodInfo;
				HarmonyMethod val2 = new HarmonyMethod(typeof(Plugin), "SwingPriority", (Type[])null);
				val.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Not found: " + text));
			}
		}
	}

	internal static bool WantsSpecial(CharacterBody body)
	{
		if (!Object.op_Implicit((Object)(object)body) || !((Object)body).name.StartsWith("FalseSonBody"))
		{
			return false;
		}
		InputBankTest inputBank = body.inputBank;
		SkillLocator skillLocator = body.skillLocator;
		return Object.op_Implicit((Object)(object)inputBank) && inputBank.skill4.down && Object.op_Implicit((Object)(object)skillLocator) && Object.op_Implicit((Object)(object)skillLocator.special) && skillLocator.special.IsReady();
	}

	private static void SwingPriority(EntityState __instance, ref InterruptPriority __result)
	{
		try
		{
			if (Object.op_Implicit((Object)(object)__instance.outer) && WantsSpecial(((Component)__instance.outer).GetComponent<CharacterBody>()))
			{
				__result = (InterruptPriority)0;
			}
		}
		catch
		{
		}
	}

	private static bool PrimaryPrefix(GenericSkill __instance, ref bool __result)
	{
		try
		{
			CharacterBody characterBody = __instance.characterBody;
			if (!Object.op_Implicit((Object)(object)characterBody) || !Object.op_Implicit((Object)(object)characterBody.skillLocator) || (Object)(object)characterBody.skillLocator.primary != (Object)(object)__instance)
			{
				return true;
			}
			if (!WantsSpecial(characterBody))
			{
				return true;
			}
			__result = false;
			return false;
		}
		catch
		{
			return true;
		}
	}
}