using System;
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 HarmonyLib;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("FunniMouthe")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FunniMouthe")]
[assembly: AssemblyTitle("FunniMouthe")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace FunniMouthe;
[BepInPlugin("FunniMouthe", "FunniMouthe", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
public static List<AudioClip> sounds = new List<AudioClip>();
private void Awake()
{
Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
LoadMouthSounds();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin FunniMouthe is loaded!");
}
[HarmonyPatch(typeof(AudioSource), "Play", new Type[] { })]
[HarmonyPrefix]
public static void Play(ref AudioSource __instance)
{
if (((Object)((Component)__instance).gameObject).name.Contains("SFX_Screamo_Scream"))
{
__instance.clip = GetRandom(sounds);
}
}
public static T GetRandom<T>(List<T> array)
{
int num = Random.Range(0, array.Count);
if (num > array.Count - 1)
{
num = array.Count - 1;
}
if (num < 0)
{
num = 0;
}
return array[num];
}
public void LoadMouthSounds()
{
try
{
List<string> list = new List<string>();
((BaseUnityPlugin)this).Logger.LogInfo((object)Paths.PluginPath);
string[] array = Directory.GetFiles(Path.Join((ReadOnlySpan<char>)Paths.PluginPath, (ReadOnlySpan<char>)"Excuze-FunniMouthe"), "*.mp3").ToArray();
list.AddRange(array);
((BaseUnityPlugin)this).Logger.LogInfo((object)GeneralExtensions.Join<string>((IEnumerable<string>)array, (Func<string, string>)null, ", "));
foreach (string item in list)
{
AudioClip val = LoadLocalAudioClip(item, (AudioType)13);
if ((Object)(object)val != (Object)null)
{
((Object)val).name = Path.GetFileNameWithoutExtension(item);
sounds.Add(val);
((BaseUnityPlugin)this).Logger.LogInfo((object)("Found & loaded custom mouth mp3 '" + Path.GetFileNameWithoutExtension(item) + "'"));
}
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Exception while loading the mouth sounds! :(\nError: " + ex));
}
}
public AudioClip LoadLocalAudioClip(string path, AudioType type)
{
//IL_0003: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Invalid comparison between Unknown and I4
AudioClip result = null;
UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path, type);
try
{
audioClip.SendWebRequest();
try
{
while (!audioClip.isDone)
{
}
if ((int)audioClip.result == 1)
{
result = DownloadHandlerAudioClip.GetContent(audioClip);
}
else
{
((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load AudioClip from path: " + path + "\n" + audioClip.error));
}
}
catch (Exception ex)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Exception encountered while loading from disk!\n" + ex.Message + " " + ex.StackTrace));
}
}
finally
{
((IDisposable)audioClip)?.Dispose();
}
return result;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "FunniMouthe";
public const string PLUGIN_NAME = "FunniMouthe";
public const string PLUGIN_VERSION = "1.0.0";
}