using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Fields;
using PluginConfig.API.Functionals;
using UltraRankSounds.Components;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("UltraRankSounds")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d3257ff444c73f7b3e40a06e9c0a7eece6f535d7")]
[assembly: AssemblyProduct("UltraRankSounds")]
[assembly: AssemblyTitle("UltraRankSounds")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace UltraRankSounds
{
internal static class PluginInfo
{
public const string GUID = "gamingnoobdev.ultrakill.UltraRankSounds";
public const string NAME = "UltraRankSounds";
public const string VERSION = "1.0.1";
}
[BepInProcess("ULTRAKILL.exe")]
[BepInPlugin("gamingnoobdev.ultrakill.UltraRankSounds", "UltraRankSounds", "1.0.1")]
public class UltraRankSounds : BaseUnityPlugin
{
[CompilerGenerated]
private static class <>O
{
public static BoolValueChangeEventDelegate <0>__ChangedModStatus;
public static OnValueChangeEventDelegate <1>__VolumeChanged;
public static OnClick <2>__OpenDefaultSoundsFolder;
}
public static string DefaultSoundParentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";
public static string DefaultSoundFolder = Path.Combine(DefaultSoundParentFolder, "sounds") ?? "";
public static string DestructiveSound = Path.Combine(DefaultSoundFolder, "D.mp3") ?? "";
public static string ChaoticSound = Path.Combine(DefaultSoundFolder, "C.mp3") ?? "";
public static string BrutalSound = Path.Combine(DefaultSoundFolder, "B.mp3") ?? "";
public static string AnarchicSound = Path.Combine(DefaultSoundFolder, "A.mp3") ?? "";
public static string SupremeSound = Path.Combine(DefaultSoundFolder, "S.mp3") ?? "";
public static string SSadisticSound = Path.Combine(DefaultSoundFolder, "SS.mp3") ?? "";
public static string SSShitstormSound = Path.Combine(DefaultSoundFolder, "SSS.mp3") ?? "";
public static string ULTRAKILLSound = Path.Combine(DefaultSoundFolder, "ULTR.mp3") ?? "";
public static FloatSliderField VolumeSlider;
public static ButtonField OpenSoundsFolder;
public static BoolField PlayIfDescended;
public static BoolField EnableSounds;
private static PluginConfigurator config;
private static void InitConfig()
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_004a: Expected O, but got Unknown
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0069: Expected O, but got Unknown
//IL_0092: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Expected O, but got Unknown
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Expected O, but got Unknown
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
//IL_00f1: Expected O, but got Unknown
//IL_010b: Unknown result type (might be due to invalid IL or missing references)
//IL_0110: Unknown result type (might be due to invalid IL or missing references)
//IL_0116: Expected O, but got Unknown
//IL_0130: Unknown result type (might be due to invalid IL or missing references)
//IL_0135: Unknown result type (might be due to invalid IL or missing references)
//IL_013b: Expected O, but got Unknown
config = PluginConfigurator.Create("UltraRankSounds", "gamingnoobdev.ultrakill.UltraRankSounds");
new ConfigHeader(config.rootPanel, "Sound settings", 24);
EnableSounds = new BoolField(config.rootPanel, "Enable rank sounds", "ultraranksounds.enabled", true);
PlayIfDescended = new BoolField(config.rootPanel, "Play sound when rank descended", "ultraranksounds.playdescended", false);
VolumeSlider = new FloatSliderField(config.rootPanel, "Volume", "ultraranksounds.volume", new Tuple<float, float>(0f, 1f), 1f, 2);
new ConfigHeader(config.rootPanel, "Sound files", 24);
OpenSoundsFolder = new ButtonField(config.rootPanel, "Open sounds folder", "ultraranksounds.opensoundsfolder");
BoolField enableSounds = EnableSounds;
object obj = <>O.<0>__ChangedModStatus;
if (obj == null)
{
BoolValueChangeEventDelegate val = ChangedModStatus;
<>O.<0>__ChangedModStatus = val;
obj = (object)val;
}
enableSounds.onValueChange += (BoolValueChangeEventDelegate)obj;
FloatSliderField volumeSlider = VolumeSlider;
object obj2 = <>O.<1>__VolumeChanged;
if (obj2 == null)
{
OnValueChangeEventDelegate val2 = VolumeChanged;
<>O.<1>__VolumeChanged = val2;
obj2 = (object)val2;
}
volumeSlider.onValueChange += (OnValueChangeEventDelegate)obj2;
ButtonField openSoundsFolder = OpenSoundsFolder;
object obj3 = <>O.<2>__OpenDefaultSoundsFolder;
if (obj3 == null)
{
OnClick val3 = OpenDefaultSoundsFolder;
<>O.<2>__OpenDefaultSoundsFolder = val3;
obj3 = (object)val3;
}
openSoundsFolder.onClick += (OnClick)obj3;
EnableSounds.TriggerValueChangeEvent();
VolumeSlider.TriggerValueChangeEvent();
}
private static void ChangedModStatus(BoolValueChangeEvent e)
{
((ConfigField)PlayIfDescended).interactable = e.value;
((ConfigField)VolumeSlider).interactable = e.value;
}
private static void VolumeChanged(FloatSliderValueChangeEvent e)
{
CustomSoundPlayer.Instance?.SetSoundVolume(e.newValue);
}
private static void OpenDefaultSoundsFolder()
{
Application.OpenURL(new Uri(DefaultSoundFolder).AbsoluteUri);
}
private void Awake()
{
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
if (!Directory.Exists(DefaultSoundFolder))
{
Directory.CreateDirectory(DefaultSoundFolder);
}
if (!File.Exists(DestructiveSound))
{
File.Move(Path.Combine(DefaultSoundParentFolder, "D.mp3") ?? "", DestructiveSound);
File.Move(Path.Combine(DefaultSoundParentFolder, "C.mp3") ?? "", ChaoticSound);
File.Move(Path.Combine(DefaultSoundParentFolder, "B.mp3") ?? "", BrutalSound);
File.Move(Path.Combine(DefaultSoundParentFolder, "A.mp3") ?? "", AnarchicSound);
File.Move(Path.Combine(DefaultSoundParentFolder, "S.mp3") ?? "", SupremeSound);
File.Move(Path.Combine(DefaultSoundParentFolder, "SS.mp3") ?? "", SSadisticSound);
File.Move(Path.Combine(DefaultSoundParentFolder, "SSS.mp3") ?? "", SSShitstormSound);
File.Move(Path.Combine(DefaultSoundParentFolder, "ULTR.mp3") ?? "", ULTRAKILLSound);
}
InitConfig();
new Harmony("gamingnoobdev.ultrakill.UltraRankSounds").PatchAll();
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "UltraRankSounds";
public const string PLUGIN_NAME = "UltraRankSounds";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace UltraRankSounds.Patches
{
[HarmonyPatch(typeof(StyleHUD))]
public class StyleHUDPatch
{
private static CustomSoundPlayer customSoundPlayer;
[HarmonyPostfix]
[HarmonyPatch(typeof(StyleHUD), "Start")]
public static void StyleHUD_Start_Postfix(GameObject ___styleHud, StyleHUD __instance)
{
customSoundPlayer = ___styleHud.AddComponent<CustomSoundPlayer>();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StyleHUD), "ComboStart")]
public static void StyleHUD_ComboStart_Postfix()
{
PlaySoundForRank(0, "destructive (hooraaay!!!)");
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StyleHUD), "AscendRank")]
public static void StyleHUD_AscendRank_Postfix(StyleHUD __instance)
{
int rankIndex = __instance.rankIndex;
string name = ((Object)__instance.currentRank.sprite).name;
PlaySoundForRank(rankIndex, name);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StyleHUD), "DescendRank")]
public static void StyleHUD_DescendRank_Postfix(bool ___comboActive, StyleHUD __instance)
{
if (UltraRankSounds.PlayIfDescended.value && ___comboActive)
{
int rankIndex = __instance.rankIndex;
string name = ((Object)__instance.currentRank.sprite).name;
PlaySoundForRank(rankIndex, name);
}
}
private static void PlaySoundForRank(int index, string name, bool ascended = true)
{
if (UltraRankSounds.EnableSounds.value)
{
string soundPathForRankIndex = GetSoundPathForRankIndex(index);
string text = (ascended ? "ascended" : "descended");
Debug.Log((object)$"{text} style rank to {name} [index: {index}] | playing sound {soundPathForRankIndex}");
customSoundPlayer.PlaySound(soundPathForRankIndex);
}
}
private static string GetSoundPathForRankIndex(int rank)
{
return rank switch
{
0 => UltraRankSounds.DestructiveSound,
1 => UltraRankSounds.ChaoticSound,
2 => UltraRankSounds.BrutalSound,
3 => UltraRankSounds.AnarchicSound,
4 => UltraRankSounds.SupremeSound,
5 => UltraRankSounds.SSadisticSound,
6 => UltraRankSounds.SSShitstormSound,
7 => UltraRankSounds.ULTRAKILLSound,
_ => "",
};
}
}
}
namespace UltraRankSounds.Components
{
public class CustomSoundPlayer : MonoBehaviour
{
private static CustomSoundPlayer _instance;
public AudioSource source;
private float soundVolume;
private string soundPath;
public static CustomSoundPlayer Instance
{
get
{
return _instance;
}
set
{
throw new NotImplementedException();
}
}
private void Start()
{
_instance = this;
source = ((Component)this).gameObject.AddComponent<AudioSource>();
SetSoundVolume(UltraRankSounds.VolumeSlider.value);
}
public void SetSoundVolume(float volume)
{
soundVolume = volume;
}
public void PlaySound(string file)
{
if (!string.IsNullOrEmpty(file))
{
if (!File.Exists(file))
{
Debug.LogError((object)("Could not find audio file '" + file + "'"));
return;
}
soundPath = file;
((Component)this).gameObject.SetActive(true);
((MonoBehaviour)this).StartCoroutine(PlaySoundRoutine());
}
}
private IEnumerator PlaySoundRoutine()
{
WaitUntil songFinished = new WaitUntil((Func<bool>)(() => Application.isFocused && !source.isPlaying));
FileInfo fileInfo = new FileInfo(soundPath);
AudioType val = CustomMusicFileBrowser.extensionTypeDict[fileInfo.Extension.ToLower()];
UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(new Uri(soundPath).AbsoluteUri, val);
try
{
DownloadHandler downloadHandler = request.downloadHandler;
DownloadHandlerAudioClip handler = (DownloadHandlerAudioClip)(object)((downloadHandler is DownloadHandlerAudioClip) ? downloadHandler : null);
handler.streamAudio = false;
request.SendWebRequest();
yield return request;
source.clip = handler.audioClip;
source.volume = soundVolume;
source.Play();
yield return songFinished;
((Component)this).gameObject.SetActive(false);
Object.Destroy((Object)(object)handler.audioClip);
}
finally
{
((IDisposable)request)?.Dispose();
}
}
}
}