using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Attack Cancel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Attack Cancel")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3d58bf75-76f5-4be7-822d-1f245bc096e3")]
[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 AttackCancel;
[BepInPlugin("IDRdh7", "Attack Cancel/Counter", "1.2.0")]
public class AttackCancel : BaseUnityPlugin
{
private static ConfigEntry<KeyCode> cancelKeyParry;
private static ConfigEntry<KeyCode> cancelKeyDodge;
private static ConfigEntry<bool> modEnabled;
private static ConfigEntry<bool> debugMessages;
private void Awake()
{
cancelKeyParry = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "Cancel Key Parry", (KeyCode)324, "Key used to cancel the attack with a parry or block.");
cancelKeyDodge = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "Cancel Key Dodge", (KeyCode)308, "Key used to cancel the attack with a dodge.");
modEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Mod Enabled", true, "Enable or disable the Attack Cancel mod.");
debugMessages = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Debug Messages", true, "Enable debug log messages.");
((BaseUnityPlugin)this).Logger.LogInfo((object)"[Attack Cancel/Counter] Loaded — Legacy input active");
Harmony.CreateAndPatchAll(typeof(AttackCancel), (string)null);
}
private void Update()
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
if (modEnabled.Value)
{
Player localPlayer = Player.m_localPlayer;
if (!((Object)(object)localPlayer == (Object)null) && (Input.GetKeyDown(cancelKeyParry.Value) || Input.GetKeyDown(cancelKeyDodge.Value)))
{
TryCancelAttack(localPlayer);
}
}
}
private void TryCancelAttack(Player player)
{
//IL_0175: Unknown result type (might be due to invalid IL or missing references)
FieldInfo field = typeof(Humanoid).GetField("m_currentAttack", BindingFlags.Instance | BindingFlags.NonPublic);
if (field == null)
{
if (debugMessages.Value)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"[Attack Cancel/Counter] m_currentAttack field not found");
}
return;
}
object? value = field.GetValue(player);
Attack val = (Attack)((value is Attack) ? value : null);
if (val == null)
{
if (debugMessages.Value)
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"[Attack Cancel/Counter] No currentAttack detected");
}
return;
}
FieldInfo field2 = typeof(Character).GetField("m_zanim", BindingFlags.Instance | BindingFlags.NonPublic);
if (field2 != null)
{
object value2 = field2.GetValue(player);
if (value2 != null)
{
MethodInfo method = value2.GetType().GetMethod("SetTrigger", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method != null)
{
method.Invoke(value2, new object[1] { "block" });
}
else if (debugMessages.Value)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"[Attack Cancel/Counter] SetTrigger method not found");
}
}
}
else if (debugMessages.Value)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"[Attack Cancel/Counter] m_zanim field not found");
}
Humanoid component = ((Component)player).GetComponent<Humanoid>();
ZSyncAnimation component2 = ((Component)player).GetComponent<ZSyncAnimation>();
field.SetValue(player, null);
((Character)component).ForceJump(new Vector3(0f, -20f, 0f), true);
if (debugMessages.Value)
{
((Character)player).Message((MessageType)2, "Attack Canceled!", 0, (Sprite)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"[Attack Cancel/Counter] Attack canceled via reflection and block trigger");
}
}
}