using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
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: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("Announce")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("Announce")]
[assembly: AssemblyTitle("Announce")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
namespace Announce
{
[BepInPlugin("Announce", "Announce", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
private AudioClip[] clips;
private static readonly string[] AUDIO_FILES = new string[8] { "destructive.wav", "chaotic.wav", "brutal.wav", "anarchic.wav", "supreme.wav", "sadistic.wav", "shitstorm.wav", "ultrakill.wav" };
private int currRankIndex;
private GameObject obj = new GameObject();
private AudioSource src;
private bool outOfCombat;
private bool allowDescendingRanks;
private float cooldownTimer;
private bool[] isInCooldown = new bool[AUDIO_FILES.Length];
private bool hasDestructivePlayed;
private async void Awake()
{
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin Announce is loaded!");
allowDescendingRanks = ((BaseUnityPlugin)this).Config.Bind<bool>("Announcer", "allowDescendingRanks", false, "Whether you want the announcer to announce decreases in rank.").Value;
cooldownTimer = ((BaseUnityPlugin)this).Config.Bind<float>("Announcer", "cooldownTimer", 10f, "The time it takes for a voice line to be ready to be played again.").Value;
Debug.Log((object)$"Allow descending ranks: {allowDescendingRanks}");
Debug.Log((object)$"Cooldown Timer: {cooldownTimer}");
currRankIndex = -1;
src = obj.AddComponent<AudioSource>();
Object.DontDestroyOnLoad((Object)(object)obj);
outOfCombat = true;
GameObject _sfxObject = new GameObject();
_ = (AudioSource)_sfxObject.AddComponent(typeof(AudioSource));
hasDestructivePlayed = false;
string[] paths = new string[AUDIO_FILES.Length];
for (int i = 0; i < AUDIO_FILES.Length; i++)
{
paths[i] = Path.Combine(Application.dataPath, "Audio", AUDIO_FILES[i]);
}
string[] array = paths;
foreach (string path in array)
{
Debug.Log((object)path);
}
clips = await LoadClip(paths);
}
private async Task<AudioClip[]> LoadClip(string[] path)
{
AudioClip[] clips = (AudioClip[])(object)new AudioClip[path.Length];
for (int i = 0; i < path.Length; i++)
{
AudioClip clip = null;
UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(path[i], (AudioType)20);
try
{
uwr.SendWebRequest();
try
{
while (!uwr.isDone)
{
await Task.Delay(5);
}
if (uwr.isNetworkError || uwr.isHttpError)
{
Debug.Log((object)(uwr.error ?? ""));
}
else
{
clip = DownloadHandlerAudioClip.GetContent(uwr);
}
}
catch (Exception ex)
{
Exception err = ex;
Debug.Log((object)(err.Message + ", " + err.StackTrace));
}
}
finally
{
((IDisposable)uwr)?.Dispose();
}
clips[i] = clip;
}
return clips;
}
private IEnumerator audioCooldown(int index)
{
yield return (object)new WaitForSeconds(cooldownTimer);
isInCooldown[index] = false;
}
private void PlayLogic(int index)
{
if (currRankIndex == index)
{
return;
}
if (allowDescendingRanks || (index > currRankIndex && !isInCooldown[index]))
{
if (src.isPlaying)
{
src.Stop();
}
src.clip = clips[index];
src.Play();
isInCooldown[index] = true;
IEnumerator enumerator = audioCooldown(index);
((MonoBehaviour)this).StartCoroutine(enumerator);
hasDestructivePlayed = true;
}
currRankIndex = index;
}
private void Update()
{
if (!((Object)(object)MonoSingleton<StyleHUD>.Instance != (Object)null))
{
return;
}
bool flag = (bool)Traverse.Create((object)MonoSingleton<StyleHUD>.Instance).Field("comboActive").GetValue();
if (!flag)
{
hasDestructivePlayed = false;
currRankIndex = -1;
}
if (flag && !outOfCombat)
{
switch (MonoSingleton<StyleHUD>.Instance.rankIndex)
{
case 0:
PlayLogic(0);
break;
case 1:
PlayLogic(1);
break;
case 2:
PlayLogic(2);
break;
case 3:
PlayLogic(3);
break;
case 4:
PlayLogic(4);
break;
case 5:
PlayLogic(5);
break;
case 6:
PlayLogic(6);
break;
case 7:
PlayLogic(7);
break;
}
}
if (MonoSingleton<EnemyTracker>.Instance.GetCurrentEnemies().Count == 0)
{
outOfCombat = true;
if (hasDestructivePlayed)
{
currRankIndex = MonoSingleton<StyleHUD>.Instance.rankIndex;
}
else
{
currRankIndex = -1;
}
}
else
{
outOfCombat = false;
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "Announce";
public const string PLUGIN_NAME = "Announce";
public const string PLUGIN_VERSION = "1.0.1";
}
}
namespace Announce.Properties
{
[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[DebuggerNonUserCode]
[CompilerGenerated]
internal class Resources
{
private static ResourceManager resourceMan;
private static CultureInfo resourceCulture;
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static ResourceManager ResourceManager
{
get
{
if (resourceMan == null)
{
ResourceManager resourceManager = new ResourceManager("Announce.Properties.Resources", typeof(Resources).Assembly);
resourceMan = resourceManager;
}
return resourceMan;
}
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
internal static CultureInfo Culture
{
get
{
return resourceCulture;
}
set
{
resourceCulture = value;
}
}
internal static UnmanagedMemoryStream ahhh => ResourceManager.GetStream("ahhh", resourceCulture);
internal Resources()
{
}
}
}