using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
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("pRankClicker")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("pRankClicker")]
[assembly: AssemblyCopyright("Copyright © 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c0f20788-4a56-4572-8cc2-b37f2c6af973")]
[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 pRankClicker;
[BepInPlugin("fidgety.pRankClicker.ultrakill", "P-Rank Clicker Mod", "1.0.5")]
public class PRankClicker : BaseUnityPlugin
{
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static AudioConfigurationChangeHandler <>9__3_0;
internal void <Awake>b__3_0(bool deviceWasChanged)
{
if (clickPath != null)
{
clickClip = AudioLoader.LoadWav(clickPath);
}
}
}
public static ManualLogSource LogSource;
public static string clickPath;
public static AudioClip clickClip;
private void Awake()
{
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Expected O, but got Unknown
//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Expected O, but got Unknown
LogSource = ((BaseUnityPlugin)this).Logger;
clickClip = null;
string[] directories = Directory.GetDirectories(Paths.PluginPath, "*PRankClicker*");
string[] array = directories;
foreach (string path in array)
{
string path2 = Path.Combine(path, "click.wav");
if (File.Exists(path2))
{
clickPath = path2;
clickClip = AudioLoader.LoadWav(path2);
break;
}
}
object obj = <>c.<>9__3_0;
if (obj == null)
{
AudioConfigurationChangeHandler val = delegate
{
if (clickPath != null)
{
clickClip = AudioLoader.LoadWav(clickPath);
}
};
<>c.<>9__3_0 = val;
obj = (object)val;
}
AudioSettings.OnAudioConfigurationChanged += (AudioConfigurationChangeHandler)obj;
if (!((Object)(object)clickClip == (Object)null))
{
Harmony val2 = new Harmony("fidgety.pRankClicker.ultrakill");
val2.PatchAll();
LogSource.LogInfo((object)"P-Rank Clicker loaded!");
}
}
}
public static class AudioLoader
{
public static AudioClip LoadWav(string path)
{
byte[] array = File.ReadAllBytes(path);
int num = array[22];
int num2 = BitConverter.ToInt32(array, 24);
int i = 44;
int num3 = (array.Length - i) / 2;
float[] array2 = new float[num3];
int num4 = 0;
for (; i < array.Length; i += 2)
{
short num5 = BitConverter.ToInt16(array, i);
array2[num4] = (float)num5 / 32768f;
num4++;
}
AudioClip val = AudioClip.Create("click", num3 / num, num, num2, false);
val.SetData(array2, 0);
return val;
}
}
public static class SoundPlayer
{
public static void PlayGlobal(AudioClip clip)
{
//IL_0013: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
if (!((Object)(object)clip == (Object)null))
{
GameObject val = new GameObject("PRankClickSound");
AudioSource val2 = val.AddComponent<AudioSource>();
val2.clip = clip;
val2.spatialBlend = 0f;
val2.volume = 1f;
val2.Play();
Object.Destroy((Object)(object)val, clip.length);
}
}
}
[HarmonyPatch(typeof(FinalRank), "SetRank")]
internal class RankPrintPatch
{
public static ManualLogSource LogSource;
private static void Postfix(string rank)
{
if (rank == "<color=#FFFFFF>P</color>")
{
SoundPlayer.PlayGlobal(PRankClicker.clickClip);
}
}
}