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("AutoParry")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AutoParry")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("7c06fbc7-8a95-4353-944c-7c12b7d946a9")]
[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")]
[BepInPlugin("auto.parry", "Auto Parry", "2.7.0")]
public class AutoParryPlugin : BaseUnityPlugin
{
public const string ModGUID = "auto.parry";
public const string ModName = "Auto Parry";
public const string ModVersion = "2.7.0";
public static ConfigEntry<float> Cooldown;
public static ConfigEntry<float> ParryRange;
public static ConfigEntry<float> MeleeTriggerDist;
public static ConfigEntry<float> MeleeMinSpeed;
public static ConfigEntry<float> ParryChance;
private void Awake()
{
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
Cooldown = ((BaseUnityPlugin)this).Config.Bind<float>("AutoParry", "CustomCooldown", 0.2f, "Cooldown between auto-parry (seconds).");
ParryRange = ((BaseUnityPlugin)this).Config.Bind<float>("AutoParry", "DetectionRange", 8f, "Projectile detection range.");
MeleeTriggerDist = ((BaseUnityPlugin)this).Config.Bind<float>("AutoParry", "MeleeTriggerDistance", 4f, "Melee detection range.");
NewMethodS();
ParryChance = ((BaseUnityPlugin)this).Config.Bind<float>("AutoParry", "ParryChance", 1f, "Chance to parry (0.0 - 1.0).");
new Harmony("auto.parry").PatchAll();
void NewMethodS()
{
MeleeMinSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("AutoParry", "MeleeMinSpeed", 15f, "Minimum enemy speed to trigger parry.");
}
}
}
[HarmonyPatch(typeof(NewMovement), "Update")]
public class AutoParryLogic
{
private static float customCooldownTimer;
private static void Postfix(NewMovement __instance)
{
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
if (customCooldownTimer > 0f)
{
customCooldownTimer -= Time.deltaTime;
return;
}
FistControl instance = MonoSingleton<FistControl>.Instance;
if ((Object)(object)instance == (Object)null || (Object)(object)instance.currentPunch == (Object)null)
{
return;
}
float value = AutoParryPlugin.ParryRange.Value;
float value2 = AutoParryPlugin.MeleeTriggerDist.Value;
float value3 = AutoParryPlugin.MeleeMinSpeed.Value;
float num = Mathf.Clamp01(AutoParryPlugin.ParryChance.Value);
Collider[] array = Physics.OverlapSphere(((Component)__instance).transform.position, value);
Projectile val = null;
Grenade val2 = null;
EnemyIdentifier val3 = null;
float num2 = float.MaxValue;
float num3 = float.MaxValue;
float num4 = float.MaxValue;
Collider[] array2 = array;
foreach (Collider val4 in array2)
{
if ((Object)(object)val4 == (Object)null)
{
continue;
}
float num5 = Vector3.Distance(((Component)__instance).transform.position, ((Component)val4).transform.position);
Projectile componentInParent = ((Component)val4).GetComponentInParent<Projectile>();
if ((Object)(object)componentInParent != (Object)null && !componentInParent.friendly && num5 < 5.5f && num5 < num2)
{
val = componentInParent;
num2 = num5;
continue;
}
Grenade componentInParent2 = ((Component)val4).GetComponentInParent<Grenade>();
if ((Object)(object)componentInParent2 != (Object)null && num5 < num3)
{
val2 = componentInParent2;
num3 = num5;
continue;
}
EnemyIdentifier componentInParent3 = ((Component)val4).GetComponentInParent<EnemyIdentifier>();
if (!((Object)(object)componentInParent3 != (Object)null))
{
continue;
}
bool flag = true;
Rigidbody componentInParent4 = ((Component)val4).GetComponentInParent<Rigidbody>();
Vector3 velocity;
if ((Object)(object)componentInParent4 != (Object)null)
{
velocity = componentInParent4.velocity;
if (((Vector3)(ref velocity)).magnitude < 0.1f)
{
flag = false;
}
}
if (flag && num5 < value2 && (Object)(object)componentInParent4 != (Object)null)
{
velocity = componentInParent4.velocity;
if (((Vector3)(ref velocity)).magnitude > value3 && num5 < num4)
{
val3 = componentInParent3;
num4 = num5;
}
}
}
if (((Object)(object)val != (Object)null || (Object)(object)val2 != (Object)null || (Object)(object)val3 != (Object)null) && Random.value <= num)
{
instance.currentPunch.PunchStart();
customCooldownTimer = AutoParryPlugin.Cooldown.Value;
}
}
}