using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Decorators;
using PluginConfig.API.Fields;
using PluginConfig.API.Functionals;
using UltraRankSounds.Components;
using UltraRankSounds.Management;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("UltraRankSounds")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5+dabccc87cfc22745f1a7e13ab9317f6e81b74437")]
[assembly: AssemblyProduct("UltraRankSounds")]
[assembly: AssemblyTitle("UltraRankSounds")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.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.6";
}
[BepInProcess("ULTRAKILL.exe")]
[BepInPlugin("gamingnoobdev.ultrakill.UltraRankSounds", "UltraRankSounds", "1.0.6")]
public class UltraRankSounds : BaseUnityPlugin
{
[CompilerGenerated]
private static class <>O
{
public static OnClick <0>__RefreshEntries;
}
[Serializable]
[CompilerGenerated]
private sealed class <>c
{
public static readonly <>c <>9 = new <>c();
public static BoolValueChangeEventDelegate <>9__16_0;
public static StringListValueChangeEventDelegate <>9__16_1;
public static OnValueChangeEventDelegate <>9__16_2;
public static OnValueChangeEventDelegate <>9__16_3;
public static OnValueChangeEventDelegate <>9__16_4;
public static OnClick <>9__16_5;
public static OnClick <>9__16_6;
internal void <InitConfig>b__16_0(BoolValueChangeEvent e)
{
((ConfigField)PlayIfDescended).interactable = e.value;
((ConfigField)PlaySoundsInLoadedOrder).interactable = e.value;
((ConfigField)EnableStyleBonusSounds).interactable = e.value;
((ConfigField)CurrentSoundPack).interactable = e.value;
((ConfigField)MasterVolumeSlider).interactable = e.value;
((ConfigField)StyleRankVolumeSlider).interactable = e.value;
((ConfigField)StyleBonusVolumeSlider).interactable = e.value;
}
internal void <InitConfig>b__16_1(StringListValueChangeEvent e)
{
SoundConfig.SetSoundPack(e.value);
QueuedCustomSoundPlayer.ClearAllSounds();
}
internal void <InitConfig>b__16_2(FloatSliderValueChangeEvent e)
{
CustomSoundPlayer.SetSoundVolumes(e.newValue * StyleRankVolumeSlider.value);
QueuedCustomSoundPlayer.SetSoundVolumes(e.newValue * StyleBonusVolumeSlider.value);
}
internal void <InitConfig>b__16_3(FloatSliderValueChangeEvent e)
{
CustomSoundPlayer.SetSoundVolumes(MasterVolumeSlider.value * e.newValue);
}
internal void <InitConfig>b__16_4(FloatSliderValueChangeEvent e)
{
QueuedCustomSoundPlayer.SetSoundVolumes(MasterVolumeSlider.value * e.newValue);
}
internal void <InitConfig>b__16_5()
{
Application.OpenURL(new Uri(SoundConfig.CurrentSoundPack.StyleRanksFolder).AbsoluteUri);
}
internal void <InitConfig>b__16_6()
{
Application.OpenURL(new Uri(SoundConfig.defaultSoundPacksFolder).AbsoluteUri);
}
}
private static readonly Dictionary<string, string> currentAvailableStylePointBonuses = new Dictionary<string, string>();
private static PluginConfigurator config;
private static ManualLogSource logger;
public static BoolField PlaySoundsInLoadedOrder;
public static BoolField EnableStyleBonusSounds;
public static BoolField PlayIfDescended;
public static BoolField EnableSounds;
public static FloatSliderField MasterVolumeSlider;
public static FloatSliderField StyleRankVolumeSlider;
public static FloatSliderField StyleBonusVolumeSlider;
public static ButtonField RefreshFiles;
public static ButtonField OpenSoundPacksFolder;
public static ButtonField OpenSoundPack;
public static StringMultilineField CurrentAvailableStylePointBonusesText;
public static StringListField CurrentSoundPack;
public static readonly Random randomNumGen = new Random();
private static void InitConfig()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Expected O, but got Unknown
//IL_006e: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Expected O, but got Unknown
//IL_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Expected O, but got Unknown
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Expected O, but got Unknown
//IL_0121: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Expected O, but got Unknown
//IL_0154: Unknown result type (might be due to invalid IL or missing references)
//IL_015e: Expected O, but got Unknown
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_0191: Expected O, but got Unknown
//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Expected O, but got Unknown
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
//IL_01f9: Expected O, but got Unknown
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Expected O, but got Unknown
//IL_022b: Unknown result type (might be due to invalid IL or missing references)
//IL_0235: Expected O, but got Unknown
//IL_0246: Unknown result type (might be due to invalid IL or missing references)
//IL_0267: Unknown result type (might be due to invalid IL or missing references)
//IL_026c: Unknown result type (might be due to invalid IL or missing references)
//IL_0278: Expected O, but got Unknown
//IL_0291: Unknown result type (might be due to invalid IL or missing references)
//IL_0296: Unknown result type (might be due to invalid IL or missing references)
//IL_029c: Expected O, but got Unknown
//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
//IL_02c5: Expected O, but got Unknown
//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
//IL_02ee: Expected O, but got Unknown
//IL_030c: Unknown result type (might be due to invalid IL or missing references)
//IL_0311: Unknown result type (might be due to invalid IL or missing references)
//IL_0317: Expected O, but got Unknown
//IL_0335: Unknown result type (might be due to invalid IL or missing references)
//IL_033a: Unknown result type (might be due to invalid IL or missing references)
//IL_0340: Expected O, but got Unknown
//IL_035e: Unknown result type (might be due to invalid IL or missing references)
//IL_0363: Unknown result type (might be due to invalid IL or missing references)
//IL_0369: Expected O, but got Unknown
//IL_0387: Unknown result type (might be due to invalid IL or missing references)
//IL_038c: Unknown result type (might be due to invalid IL or missing references)
//IL_0392: Expected O, but got Unknown
//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
//IL_03b1: Unknown result type (might be due to invalid IL or missing references)
//IL_03b7: Expected O, but got Unknown
config = PluginConfigurator.Create("UltraRankSounds", "gamingnoobdev.ultrakill.UltraRankSounds");
config.SetIconWithURL("https://raw.githubusercontent.com/GAMINGNOOBdev/UltraRankSounds/refs/heads/master/icon.png");
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", true);
PlaySoundsInLoadedOrder = new BoolField(config.rootPanel, "Play sounds in loaded order", "ultraranksounds.playinloadedorder", false);
EnableStyleBonusSounds = new BoolField(config.rootPanel, "Enable sounds for style bonuses", "ultraranksounds.playsoundsforstylebonuses", false);
List<string> list = new List<string>(1) { "default" };
foreach (string key in SoundConfig.SoundPacks.Keys)
{
list.Add(key);
}
CurrentSoundPack = new StringListField(config.rootPanel, "Selected sound pack", "ultraranksounds.currentsoundpack", list.ToArray(), "default");
MasterVolumeSlider = new FloatSliderField(config.rootPanel, "Volume", "ultraranksounds.volume", new Tuple<float, float>(0f, 1f), 1f, 2);
StyleRankVolumeSlider = new FloatSliderField(config.rootPanel, "Style rank volume", "ultraranksounds.stylerankvolume", new Tuple<float, float>(0f, 1f), 1f, 2);
StyleBonusVolumeSlider = new FloatSliderField(config.rootPanel, "Style bonus volume", "ultraranksounds.stylebonusvolume", new Tuple<float, float>(0f, 1f), 0.5f, 2);
new ConfigHeader(config.rootPanel, "Management", 24);
OpenSoundPack = new ButtonField(config.rootPanel, "Open sound pack", "ultraranksounds.opensoundpack");
OpenSoundPacksFolder = new ButtonField(config.rootPanel, "Open sound packs folder", "ultraranksounds.opensoundpacksfolder");
RefreshFiles = new ButtonField(config.rootPanel, "Refresh all files", "ultraranksounds.refreshall");
new ConfigHeader(config.rootPanel, "Currently Available Style Point Bonuses", 24);
CurrentAvailableStylePointBonusesText = new StringMultilineField(config.rootPanel, "", "ultraranksounds.curravailablestylebonuses", "", true, false)
{
interactable = false
};
BoolField enableSounds = EnableSounds;
object obj = <>c.<>9__16_0;
if (obj == null)
{
BoolValueChangeEventDelegate val = delegate(BoolValueChangeEvent e)
{
((ConfigField)PlayIfDescended).interactable = e.value;
((ConfigField)PlaySoundsInLoadedOrder).interactable = e.value;
((ConfigField)EnableStyleBonusSounds).interactable = e.value;
((ConfigField)CurrentSoundPack).interactable = e.value;
((ConfigField)MasterVolumeSlider).interactable = e.value;
((ConfigField)StyleRankVolumeSlider).interactable = e.value;
((ConfigField)StyleBonusVolumeSlider).interactable = e.value;
};
<>c.<>9__16_0 = val;
obj = (object)val;
}
enableSounds.onValueChange += (BoolValueChangeEventDelegate)obj;
StringListField currentSoundPack = CurrentSoundPack;
object obj2 = <>c.<>9__16_1;
if (obj2 == null)
{
StringListValueChangeEventDelegate val2 = delegate(StringListValueChangeEvent e)
{
SoundConfig.SetSoundPack(e.value);
QueuedCustomSoundPlayer.ClearAllSounds();
};
<>c.<>9__16_1 = val2;
obj2 = (object)val2;
}
currentSoundPack.onValueChange += (StringListValueChangeEventDelegate)obj2;
FloatSliderField masterVolumeSlider = MasterVolumeSlider;
object obj3 = <>c.<>9__16_2;
if (obj3 == null)
{
OnValueChangeEventDelegate val3 = delegate(FloatSliderValueChangeEvent e)
{
CustomSoundPlayer.SetSoundVolumes(e.newValue * StyleRankVolumeSlider.value);
QueuedCustomSoundPlayer.SetSoundVolumes(e.newValue * StyleBonusVolumeSlider.value);
};
<>c.<>9__16_2 = val3;
obj3 = (object)val3;
}
masterVolumeSlider.onValueChange += (OnValueChangeEventDelegate)obj3;
FloatSliderField styleRankVolumeSlider = StyleRankVolumeSlider;
object obj4 = <>c.<>9__16_3;
if (obj4 == null)
{
OnValueChangeEventDelegate val4 = delegate(FloatSliderValueChangeEvent e)
{
CustomSoundPlayer.SetSoundVolumes(MasterVolumeSlider.value * e.newValue);
};
<>c.<>9__16_3 = val4;
obj4 = (object)val4;
}
styleRankVolumeSlider.onValueChange += (OnValueChangeEventDelegate)obj4;
FloatSliderField styleBonusVolumeSlider = StyleBonusVolumeSlider;
object obj5 = <>c.<>9__16_4;
if (obj5 == null)
{
OnValueChangeEventDelegate val5 = delegate(FloatSliderValueChangeEvent e)
{
QueuedCustomSoundPlayer.SetSoundVolumes(MasterVolumeSlider.value * e.newValue);
};
<>c.<>9__16_4 = val5;
obj5 = (object)val5;
}
styleBonusVolumeSlider.onValueChange += (OnValueChangeEventDelegate)obj5;
ButtonField openSoundPack = OpenSoundPack;
object obj6 = <>c.<>9__16_5;
if (obj6 == null)
{
OnClick val6 = delegate
{
Application.OpenURL(new Uri(SoundConfig.CurrentSoundPack.StyleRanksFolder).AbsoluteUri);
};
<>c.<>9__16_5 = val6;
obj6 = (object)val6;
}
openSoundPack.onClick += (OnClick)obj6;
ButtonField openSoundPacksFolder = OpenSoundPacksFolder;
object obj7 = <>c.<>9__16_6;
if (obj7 == null)
{
OnClick val7 = delegate
{
Application.OpenURL(new Uri(SoundConfig.defaultSoundPacksFolder).AbsoluteUri);
};
<>c.<>9__16_6 = val7;
obj7 = (object)val7;
}
openSoundPacksFolder.onClick += (OnClick)obj7;
ButtonField refreshFiles = RefreshFiles;
object obj8 = <>O.<0>__RefreshEntries;
if (obj8 == null)
{
OnClick val8 = SoundConfig.RefreshEntries;
<>O.<0>__RefreshEntries = val8;
obj8 = (object)val8;
}
refreshFiles.onClick += (OnClick)obj8;
EnableSounds.TriggerValueChangeEvent();
CurrentSoundPack.TriggerValueChangeEvent();
MasterVolumeSlider.TriggerValueChangeEvent();
StyleRankVolumeSlider.TriggerValueChangeEvent();
StyleBonusVolumeSlider.TriggerValueChangeEvent();
}
private void Awake()
{
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
logger = ((BaseUnityPlugin)this).Logger;
SoundConfig.LoadSoundPacks();
SoundConfig.UpdateSoundEntries();
InitConfig();
new Harmony("gamingnoobdev.ultrakill.UltraRankSounds").PatchAll();
Log("Default sound pack folder: '" + SoundConfig.CurrentSoundPack.StyleRanksFolder + "'");
Log("Default sound pack style bonus folder: '" + SoundConfig.CurrentSoundPack.StyleBonusesFolder + "'");
Log("Sound packs folder: '" + SoundConfig.defaultSoundPacksFolder + "'");
}
public static bool IsStyleBonus(string bonus)
{
return currentAvailableStylePointBonuses.ContainsKey(bonus);
}
public static void RegisterStylePointBonuses(Dictionary<string, string> styleBonusses)
{
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_001f: Expected O, but got Unknown
if (styleBonusses == null)
{
Log("unable to register style point bonuses: no style bonuses dict found");
return;
}
currentAvailableStylePointBonuses.Clear();
FormattedStringBuilder val = new FormattedStringBuilder();
foreach (string key in styleBonusses.Keys)
{
string text = styleBonusses[key];
if (!Utility.IsNullOrWhiteSpace(text))
{
currentAvailableStylePointBonuses.Add(key, text);
val.Append(text + " - " + key + "\n");
}
}
CurrentAvailableStylePointBonusesText.value = val.Build().rawString;
CurrentAvailableStylePointBonusesText.TriggerValueChangeEvent();
}
public static void Log(string message, bool error = false)
{
if (logger != null)
{
if (error)
{
logger.LogError((object)message);
}
else
{
logger.LogInfo((object)message);
}
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "UltraRankSounds";
public const string PLUGIN_NAME = "UltraRankSounds";
public const string PLUGIN_VERSION = "1.0.5";
}
}
namespace UltraRankSounds.Patches
{
[HarmonyPatch(typeof(StyleHUD))]
public class StyleHUDPatch
{
private static CustomSoundPlayer styleRankSoundPlayer;
private static QueuedCustomSoundPlayer styleBonusSoundPlayer;
private static int lastRankIndex;
[HarmonyPostfix]
[HarmonyPatch(typeof(StyleHUD), "Start")]
public static void StyleHUD_Start_Postfix(GameObject ___styleHud, StyleHUD __instance)
{
styleRankSoundPlayer = ___styleHud.AddComponent<CustomSoundPlayer>();
styleBonusSoundPlayer = ___styleHud.AddComponent<QueuedCustomSoundPlayer>();
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StyleHUD), "Awake")]
public static void StyleHUD_Awake_Postfix(Dictionary<string, string> ___idNameDict)
{
UltraRankSounds.RegisterStylePointBonuses(___idNameDict);
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StyleHUD), "ComboStart")]
public static void StyleHUD_ComboStart_Postfix()
{
if (UltraRankSounds.EnableSounds.value && UltraRankSounds.PlayIfDescended.value)
{
PlaySoundForRank(0, "RankD");
}
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StyleHUD), "AddPoints")]
public static void StyleHUD_AddPoints_Postfix(string pointID, StyleHUD __instance)
{
if (UltraRankSounds.EnableSounds.value && UltraRankSounds.EnableStyleBonusSounds.value)
{
string localizedName = __instance.GetLocalizedName(pointID);
if (!string.IsNullOrWhiteSpace(localizedName) && !string.IsNullOrWhiteSpace(pointID))
{
UltraRankSounds.Log("got style bonus '" + localizedName + "' with id '" + pointID + "'");
PlaySoundForBonus(pointID);
}
}
}
[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);
lastRankIndex = rankIndex;
}
[HarmonyPostfix]
[HarmonyPatch(typeof(StyleHUD), "DescendRank")]
public static void StyleHUD_DescendRank_Postfix(bool ___comboActive, StyleHUD __instance)
{
if (UltraRankSounds.EnableSounds.value && UltraRankSounds.PlayIfDescended.value && ___comboActive)
{
int rankIndex = __instance.rankIndex;
string name = ((Object)__instance.currentRank.sprite).name;
UltraRankSounds.Log($"style rank [index: {rankIndex} oldindex: {lastRankIndex}] | name '{name}'");
PlaySoundForRank(rankIndex, name, ascended: false);
lastRankIndex = rankIndex;
}
}
private static void PlaySoundForRank(int index, string name, bool ascended = true)
{
if (UltraRankSounds.EnableSounds.value && !((Object)(object)styleRankSoundPlayer == (Object)null))
{
string soundPathForRankIndex = GetSoundPathForRankIndex(index, ascended);
string text = (ascended ? "ascended" : "descended");
UltraRankSounds.Log($"{text} style rank to '{name}' [index: {index} oldindex: {lastRankIndex}] | playing sound '{soundPathForRankIndex}'");
styleRankSoundPlayer.PlaySound(soundPathForRankIndex);
}
}
private static void PlaySoundForBonus(string id)
{
if (UltraRankSounds.EnableSounds.value && !((Object)(object)styleBonusSoundPlayer == (Object)null))
{
string pointBonusSound = SoundConfig.GetPointBonusSound(id);
if (string.IsNullOrEmpty(pointBonusSound))
{
UltraRankSounds.Log("Unable to find rank sound for point bonus '" + id + "'", error: true);
return;
}
UltraRankSounds.Log(id + " style bonus registered | playing sound '" + pointBonusSound + "'");
styleBonusSoundPlayer.QueueSound(pointBonusSound);
}
}
private static string GetSoundPathForRankIndex(int rank, bool ascended)
{
if (ascended)
{
return SoundConfig.GetAscensionRankSoundName(rank);
}
return SoundConfig.GetDescensionRankSoundName(rank);
}
}
}
namespace UltraRankSounds.Management
{
public class SoundCollection
{
private int cursor;
public List<string> Sounds { get; private set; }
public SoundCollection()
{
Sounds = new List<string>();
}
public void AddSound(string soundfile)
{
Sounds.Add(soundfile);
}
public void Clear()
{
Sounds.Clear();
cursor = 0;
}
public string DecideSound()
{
if (Sounds.Count == 0)
{
return "none";
}
if (UltraRankSounds.PlaySoundsInLoadedOrder.value)
{
cursor++;
cursor %= Sounds.Count;
return Sounds[cursor];
}
return Sounds[UltraRankSounds.randomNumGen.Next(0, Sounds.Count)];
}
}
public class SoundConfig
{
public static readonly string defaultSoundParentFolder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";
public static readonly string defaultSoundPacksFolder = Path.Combine(defaultSoundParentFolder, "soundpacks") ?? "";
private static readonly SoundPack defaultSoundPack = new SoundPack(Path.Combine(defaultSoundParentFolder, "sounds") ?? "");
public static readonly Dictionary<string, SoundPack> SoundPacks = new Dictionary<string, SoundPack>();
public static SoundPack CurrentSoundPack = defaultSoundPack;
public static void RefreshEntries()
{
string value = UltraRankSounds.CurrentSoundPack.value;
foreach (string key in SoundPacks.Keys)
{
_ = key;
UltraRankSounds.CurrentSoundPack.RemoveAt(1);
}
LoadSoundPacks();
foreach (string key2 in SoundPacks.Keys)
{
UltraRankSounds.CurrentSoundPack.AddValue(key2);
}
if (SoundPacks.ContainsKey(value))
{
UltraRankSounds.CurrentSoundPack.value = value;
}
UpdateSoundEntries();
}
public static void LoadSoundPacks()
{
SoundPacks.Clear();
if (!Directory.Exists(defaultSoundPacksFolder))
{
Directory.CreateDirectory(defaultSoundPacksFolder);
return;
}
string[] directories = Directory.GetDirectories(defaultSoundPacksFolder, "*", new EnumerationOptions
{
RecurseSubdirectories = false
});
if (directories.Length != 0)
{
string[] array = directories;
foreach (string text in array)
{
string fileName = Path.GetFileName(text);
SoundPacks.Add(fileName, new SoundPack(text));
}
}
}
public static void SetSoundPack(string name)
{
if (name == "default")
{
CurrentSoundPack = defaultSoundPack;
}
else if (SoundPacks.ContainsKey(name))
{
CurrentSoundPack = SoundPacks[name];
UpdateSoundEntries();
UltraRankSounds.Log("Changed sound pack to '" + name + "'");
}
}
public static string GetPointBonusSound(string id)
{
return CurrentSoundPack.GetPointBonusSound(id);
}
public static string GetAscensionRankSoundName(int rank)
{
return CurrentSoundPack.GetAscensionRankSoundName(rank);
}
public static string GetDescensionRankSoundName(int rank)
{
return CurrentSoundPack.GetDescensionRankSoundName(rank);
}
public static void UpdateSoundEntries()
{
CurrentSoundPack.UpdateSoundEntries();
}
}
public class SoundPack
{
private readonly StyleRankSoundCollection downrankSounds;
private readonly StyleRankSoundCollection uprankSounds;
private readonly Dictionary<string, string> styleBonuses;
public string StyleRanksFolder { get; private set; }
public string StyleBonusesFolder { get; set; }
public SoundPack(string packFolderPath)
{
StyleRanksFolder = packFolderPath;
StyleBonusesFolder = Path.Combine(StyleRanksFolder, "stylebonuses") ?? "";
styleBonuses = new Dictionary<string, string>();
uprankSounds = new StyleRankSoundCollection(null, "downrank-");
downrankSounds = new StyleRankSoundCollection("downrank-");
}
public string GetAscensionRankSoundName(int rank)
{
return uprankSounds.DecideSound(rank);
}
public string GetDescensionRankSoundName(int rank)
{
return downrankSounds.DecideSound(rank);
}
public string GetPointBonusSound(string id)
{
if (!styleBonuses.ContainsKey(id))
{
return null;
}
return styleBonuses[id];
}
public void UpdateSoundEntries()
{
string[] files = Directory.GetFiles(StyleRanksFolder, "*", SearchOption.TopDirectoryOnly);
if (files.Length == 0)
{
UltraRankSounds.Log("Cannot find any sound files for soundpack at '" + StyleRanksFolder + "'", error: true);
}
else
{
uprankSounds.RegisterSounds(ref files);
downrankSounds.RegisterSounds(ref files);
}
styleBonuses.Clear();
if (!Directory.Exists(StyleBonusesFolder))
{
UltraRankSounds.Log("no style bonus directory ('" + StyleBonusesFolder + "')");
return;
}
string[] files2 = Directory.GetFiles(StyleBonusesFolder, "*", SearchOption.TopDirectoryOnly);
UltraRankSounds.Log($"found the desired style bonus directory with {files2.Length} items ('{StyleBonusesFolder}')");
string[] array = files2;
foreach (string text in array)
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text);
styleBonuses.Add(fileNameWithoutExtension, text);
}
UltraRankSounds.Log("Registered style bonuses '" + string.Join(",", new ReadOnlySpan<string>(styleBonuses.Keys.ToArray()).ToArray()) + "'");
}
}
public class SoundRanks
{
public static readonly int DESTRUCTIVE = 0;
public static readonly int CHAOTIC = 1;
public static readonly int BRUTAL = 2;
public static readonly int ANARCHIC = 3;
public static readonly int SUPREME = 4;
public static readonly int SSADISTIC = 5;
public static readonly int SSSHITSTORM = 6;
public static readonly int ULTRAKILL = 7;
}
public class StyleRankSoundCollection
{
private readonly string prefix;
private readonly string discardPrefix;
public SoundCollection DestructiveSound;
public SoundCollection ChaoticSound;
public SoundCollection BrutalSound;
public SoundCollection AnarchicSound;
public SoundCollection SupremeSound;
public SoundCollection SSadisticSound;
public SoundCollection SSShitstormSound;
public SoundCollection ULTRAKILLSound;
public StyleRankSoundCollection(string namePrefix, string discardNamePrefix = null)
{
DestructiveSound = new SoundCollection();
ChaoticSound = new SoundCollection();
BrutalSound = new SoundCollection();
AnarchicSound = new SoundCollection();
SupremeSound = new SoundCollection();
SSadisticSound = new SoundCollection();
SSShitstormSound = new SoundCollection();
ULTRAKILLSound = new SoundCollection();
prefix = namePrefix;
discardPrefix = discardNamePrefix;
if (prefix == null)
{
prefix = "";
}
}
public void RegisterSounds(ref string[] files)
{
DestructiveSound.Clear();
ChaoticSound.Clear();
BrutalSound.Clear();
AnarchicSound.Clear();
SupremeSound.Clear();
SSadisticSound.Clear();
SSShitstormSound.Clear();
ULTRAKILLSound.Clear();
string[] array = files;
foreach (string text in array)
{
string fileName = Path.GetFileName(text);
if ((discardPrefix == null || !fileName.StartsWith(discardPrefix)) && fileName.StartsWith(prefix))
{
string text2 = fileName;
int length = prefix.Length;
fileName = text2.Substring(length, text2.Length - length);
if (fileName.StartsWith("ULTR"))
{
ULTRAKILLSound.AddSound(text);
}
else if (fileName.StartsWith("SSS"))
{
SSShitstormSound.AddSound(text);
}
else if (fileName.StartsWith("SS"))
{
SSadisticSound.AddSound(text);
}
else if (fileName.StartsWith("S"))
{
SupremeSound.AddSound(text);
}
else if (fileName.StartsWith("D"))
{
DestructiveSound.AddSound(text);
}
else if (fileName.StartsWith("C"))
{
ChaoticSound.AddSound(text);
}
else if (fileName.StartsWith("B"))
{
BrutalSound.AddSound(text);
}
else if (fileName.StartsWith("A"))
{
AnarchicSound.AddSound(text);
}
}
}
UltraRankSounds.Log("Loaded Sounds");
UltraRankSounds.Log("ULTRAKILL '" + string.Join(",", ULTRAKILLSound.Sounds.ToArray()) + "'");
UltraRankSounds.Log("SSShitstorm '" + string.Join(",", SSShitstormSound.Sounds.ToArray()) + "'");
UltraRankSounds.Log("SSadistic '" + string.Join(",", SSadisticSound.Sounds.ToArray()) + "'");
UltraRankSounds.Log("Supreme '" + string.Join(",", SupremeSound.Sounds.ToArray()) + "'");
UltraRankSounds.Log("Destructive '" + string.Join(",", DestructiveSound.Sounds.ToArray()) + "'");
UltraRankSounds.Log("Chaotic '" + string.Join(",", ChaoticSound.Sounds.ToArray()) + "'");
UltraRankSounds.Log("Brutal '" + string.Join(",", BrutalSound.Sounds.ToArray()) + "'");
UltraRankSounds.Log("Anarchic '" + string.Join(",", AnarchicSound.Sounds.ToArray()) + "'");
}
public string DecideSound(int rank)
{
if (rank == SoundRanks.DESTRUCTIVE)
{
return DestructiveSound.DecideSound();
}
if (rank == SoundRanks.CHAOTIC)
{
return ChaoticSound.DecideSound();
}
if (rank == SoundRanks.BRUTAL)
{
return BrutalSound.DecideSound();
}
if (rank == SoundRanks.ANARCHIC)
{
return AnarchicSound.DecideSound();
}
if (rank == SoundRanks.SUPREME)
{
return SupremeSound.DecideSound();
}
if (rank == SoundRanks.SSADISTIC)
{
return SSadisticSound.DecideSound();
}
if (rank == SoundRanks.SSSHITSTORM)
{
return SSShitstormSound.DecideSound();
}
if (rank == SoundRanks.ULTRAKILL)
{
return ULTRAKILLSound.DecideSound();
}
return "";
}
}
}
namespace UltraRankSounds.Components
{
public class CustomSoundPlayer : MonoBehaviour
{
private static readonly List<CustomSoundPlayer> instances = new List<CustomSoundPlayer>();
public AudioSource source;
private float soundVolume;
private string soundPath;
public static void SetSoundVolumes(float volume)
{
foreach (CustomSoundPlayer instance in instances)
{
instance.SetSoundVolume(volume);
}
}
private void Start()
{
instances.Add(this);
source = ((Component)this).gameObject.AddComponent<AudioSource>();
SetSoundVolumes(1f);
UltraRankSounds.MasterVolumeSlider.TriggerValueChangeEvent();
}
public void SetSoundVolume(float volume)
{
soundVolume = volume;
}
public void PlaySound(string file)
{
if (!string.IsNullOrEmpty(file))
{
if (!File.Exists(file))
{
UltraRankSounds.Log("Could not find audio file '" + file + "'", error: true);
return;
}
soundPath = file;
((Component)this).gameObject.SetActive(true);
((MonoBehaviour)this).StartCoroutine(PlaySoundRoutine());
}
}
private IEnumerator PlaySoundRoutine()
{
WaitUntil soundFinished = 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 soundFinished;
((Component)this).gameObject.SetActive(false);
Object.Destroy((Object)(object)handler.audioClip);
}
finally
{
((IDisposable)request)?.Dispose();
}
}
}
public class QueuedCustomSoundPlayer : MonoBehaviour
{
private static readonly List<QueuedCustomSoundPlayer> instances = new List<QueuedCustomSoundPlayer>();
private readonly ConcurrentQueue<string> sounds = new ConcurrentQueue<string>();
private AudioSource source;
private float soundVolume;
public static void SetSoundVolumes(float volume)
{
foreach (QueuedCustomSoundPlayer instance in instances)
{
instance.SetSoundVolume(volume);
}
}
public static void ClearAllSounds()
{
foreach (QueuedCustomSoundPlayer instance in instances)
{
instance.sounds.Clear();
}
}
private void Start()
{
instances.Add(this);
source = ((Component)this).gameObject.AddComponent<AudioSource>();
SetSoundVolumes(1f);
UltraRankSounds.MasterVolumeSlider.TriggerValueChangeEvent();
}
private void FixedUpdate()
{
if (!source.isPlaying && !sounds.IsEmpty)
{
((MonoBehaviour)this).StartCoroutine(PlaySoundRoutine());
}
}
public void SetSoundVolume(float volume)
{
soundVolume = volume;
}
public void QueueSound(string file)
{
if (string.IsNullOrEmpty(file))
{
return;
}
if (!File.Exists(file))
{
UltraRankSounds.Log("Could not find audio file '" + file + "'", error: true);
return;
}
sounds.Enqueue(file);
((Component)this).gameObject.SetActive(true);
List<string> list = new List<string>();
foreach (string sound in sounds)
{
list.Add(Path.GetFileNameWithoutExtension(sound));
}
UltraRankSounds.Log(string.Join(",", list));
}
private IEnumerator PlaySoundRoutine()
{
string result = null;
while (!sounds.TryDequeue(out result) && !sounds.IsEmpty)
{
}
if (result != null)
{
WaitUntil soundFinished = new WaitUntil((Func<bool>)(() => Application.isFocused && !source.isPlaying));
FileInfo fileInfo = new FileInfo(result);
AudioType val = CustomMusicFileBrowser.extensionTypeDict[fileInfo.Extension.ToLower()];
UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(new Uri(result).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 soundFinished;
Object.Destroy((Object)(object)handler.audioClip);
}
finally
{
((IDisposable)request)?.Dispose();
}
}
}
}
}