using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SilksongFaah")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SilksongFaah")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d058bf94-8550-4973-abf5-b981f0dbe537")]
[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("com.mikey.silksongfaah", "Silksong Faah", "1.0.0")]
public class SilksongFaah : BaseUnityPlugin
{
[CompilerGenerated]
private sealed class <LoadFaahCoroutine>d__6 : IEnumerator<object>, IDisposable, IEnumerator
{
private int <>1__state;
private object <>2__current;
public SilksongFaah <>4__this;
private string <pluginDir>5__1;
private string <fileName>5__2;
private string <fullPath>5__3;
private string <uri>5__4;
private UnityWebRequest <uwr>5__5;
private Exception <ex>5__6;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <LoadFaahCoroutine>d__6(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
int num = <>1__state;
if (num == -3 || num == 1)
{
try
{
}
finally
{
<>m__Finally1();
}
}
<pluginDir>5__1 = null;
<fileName>5__2 = null;
<fullPath>5__3 = null;
<uri>5__4 = null;
<uwr>5__5 = null;
<ex>5__6 = null;
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Invalid comparison between Unknown and I4
bool result;
try
{
switch (<>1__state)
{
default:
result = false;
break;
case 0:
<>1__state = -1;
<pluginDir>5__1 = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
<fileName>5__2 = "faah.wav";
<fullPath>5__3 = Path.Combine(<pluginDir>5__1, <fileName>5__2);
if (!File.Exists(<fullPath>5__3))
{
_log.LogWarning((object)("[Silksong Faah] " + <fileName>5__2 + " not found in " + <pluginDir>5__1 + ". Place your faah.mp3 there."));
result = false;
}
else
{
<uri>5__4 = "file:///" + <fullPath>5__3.Replace("\\", "/");
<uwr>5__5 = UnityWebRequestMultimedia.GetAudioClip(<uri>5__4, (AudioType)20);
<>1__state = -3;
<>2__current = <uwr>5__5.SendWebRequest();
<>1__state = 1;
result = true;
}
break;
case 1:
{
<>1__state = -3;
try
{
if ((int)<uwr>5__5.result != 1)
{
_log.LogError((object)("[Silksong Faah] Failed to load " + <fileName>5__2 + ": " + <uwr>5__5.error));
result = false;
}
else
{
_faahClip = DownloadHandlerAudioClip.GetContent(<uwr>5__5);
if (!((Object)(object)_faahClip == (Object)null))
{
((Object)_faahClip).name = Path.GetFileNameWithoutExtension(<fullPath>5__3);
_log.LogInfo((object)("[Silksong Faah] Successfully loaded " + <fileName>5__2));
goto IL_01fd;
}
_log.LogError((object)"[Silksong Faah] Loaded file but could not create AudioClip.");
result = false;
}
}
catch (Exception ex)
{
<ex>5__6 = ex;
_log.LogError((object)$"[Silksong Faah] Exception processing faah.mp3: {<ex>5__6}");
goto IL_01fd;
}
<>m__Finally1();
break;
}
IL_01fd:
<>m__Finally1();
<uwr>5__5 = null;
result = false;
break;
}
}
catch
{
//try-fault
((IDisposable)this).Dispose();
throw;
}
return result;
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
private void <>m__Finally1()
{
<>1__state = -1;
if (<uwr>5__5 != null)
{
((IDisposable)<uwr>5__5).Dispose();
}
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static ManualLogSource _log;
private static AudioClip _faahClip;
private static AudioSource _audioSource;
private static double _lastFaahTime = -999.0;
private const double FaahCooldown = 0.5;
private void Awake()
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
_log = ((BaseUnityPlugin)this).Logger;
_audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
_audioSource.spatialBlend = 0f;
_audioSource.volume = 1f;
_audioSource.playOnAwake = false;
Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
Harmony val = new Harmony("com.mikey.silksongfaah");
TryPatch(val, "GameManager", "PlayerDead");
List<MethodBase> patched = val.GetPatchedMethods().ToList();
debugLogging(patched);
((MonoBehaviour)this).StartCoroutine(LoadFaahCoroutine());
}
[IteratorStateMachine(typeof(<LoadFaahCoroutine>d__6))]
private IEnumerator LoadFaahCoroutine()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <LoadFaahCoroutine>d__6(0)
{
<>4__this = this
};
}
private static void PlayFaah()
{
try
{
if ((Object)(object)_faahClip == (Object)null || (Object)(object)_audioSource == (Object)null)
{
return;
}
double timeAsDouble = Time.timeAsDouble;
if (!(timeAsDouble - _lastFaahTime < 0.5))
{
_lastFaahTime = timeAsDouble;
_audioSource.PlayOneShot(_faahClip, 1f);
ManualLogSource log = _log;
if (log != null)
{
log.LogDebug((object)"[Silksong Faah] Played faah");
}
}
}
catch (Exception arg)
{
ManualLogSource log2 = _log;
if (log2 != null)
{
log2.LogError((object)$"[Silksong Faah] Error playing faah: {arg}");
}
}
}
private void TryPatch(Harmony harmony, string typeName, string methodName)
{
//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: Expected O, but got Unknown
try
{
Type type = AppDomain.CurrentDomain.GetAssemblies().SelectMany(delegate(Assembly a)
{
try
{
return a.GetTypes();
}
catch
{
return new Type[0];
}
}).FirstOrDefault((Type t) => t.Name == typeName);
if (type == null)
{
_log.LogWarning((object)("[Silksong Faah] Could not find type: " + typeName));
return;
}
MethodInfo method = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
if (method == null)
{
_log.LogWarning((object)("[Silksong Faah] Could not find method: " + typeName + "." + methodName));
return;
}
HarmonyMethod val = new HarmonyMethod(typeof(SilksongFaah).GetMethod("UniversalDamagePostfix", BindingFlags.Static | BindingFlags.NonPublic));
harmony.Patch((MethodBase)method, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
_log.LogInfo((object)("[Silksong Faah] Successfully patched " + typeName + "." + methodName));
}
catch (Exception arg)
{
_log.LogError((object)$"[Silksong Faah] Failed to patch {typeName}.{methodName}: {arg}");
}
}
private static void UniversalDamagePostfix()
{
PlayFaah();
}
private void debugLogging(List<MethodBase> patched)
{
_log.LogInfo((object)$"[Silksong Faah] Total patched methods: {patched.Count}");
foreach (MethodBase item in patched)
{
_log.LogInfo((object)("[Silksong Faah] Patched: " + item.DeclaringType?.Name + "." + item.Name));
}
_log.LogInfo((object)"[Silksong Faah] Plugin loaded and initialised");
}
}