using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
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("RefundSilkOnFailedParry")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RefundSilkOnFailedParry")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("91c9ba1d-05fb-45fb-9aa7-37bebd34dbca")]
[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("silksong.parry.refund.onfail.correct", "Refund Silk On Failed Cross Stitch", "2.0.0")]
[BepInProcess("Hollow Knight Silksong.exe")]
public class RefundSilkOnFailedCrossStitch : BaseUnityPlugin
{
[HarmonyPatch(typeof(PlayMakerFSM), "SendEvent")]
private static class ParryStartPatch
{
private static void Prefix(string eventName)
{
if (!(eventName != "PARRY"))
{
parryActive = true;
if (refundRoutine != null)
{
((MonoBehaviour)HeroController.instance).StopCoroutine(refundRoutine);
refundRoutine = null;
}
refundRoutine = ((MonoBehaviour)HeroController.instance).StartCoroutine(RefundIfFailed());
Log.LogInfo((object)"[Parry] Attempt started (FSM PARRY)");
}
}
}
[HarmonyPatch(typeof(HeroController), "CrossStitchInvuln")]
private static class ParrySuccessPatch
{
private static void Prefix()
{
if (parryActive)
{
parryActive = false;
if (refundRoutine != null)
{
((MonoBehaviour)HeroController.instance).StopCoroutine(refundRoutine);
refundRoutine = null;
}
Log.LogInfo((object)"[Parry] Success detected — no refund");
}
}
}
[CompilerGenerated]
private sealed class <RefundIfFailed>d__8 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <RefundIfFailed>d__8(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(ResolveWindow.Value);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if (parryActive)
{
HeroController.instance.AddSilk(SilkRefund.Value, false);
Log.LogInfo((object)$"[Parry] Failed — refunded {SilkRefund.Value} silk");
}
parryActive = false;
refundRoutine = null;
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static ConfigEntry<int> SilkRefund;
private static ConfigEntry<float> ResolveWindow;
private static bool parryActive;
private static Coroutine refundRoutine;
private static ManualLogSource Log;
private void Awake()
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
SilkRefund = ((BaseUnityPlugin)this).Config.Bind<int>("Parry", "Silk Refund On Failure", 4, "Silk refunded when Cross Stitch parry fails");
ResolveWindow = ((BaseUnityPlugin)this).Config.Bind<float>("Parry", "Resolve Window (seconds)", 1.4f, "Time to wait for Cross Stitch success before refunding silk");
Log = ((BaseUnityPlugin)this).Logger;
new Harmony("silksong.parry.refund.onfail.correct.harmony").PatchAll();
Log.LogInfo((object)"Refund Silk On Failed Cross Stitch loaded");
}
[IteratorStateMachine(typeof(<RefundIfFailed>d__8))]
private static IEnumerator RefundIfFailed()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <RefundIfFailed>d__8(0);
}
}