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 BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("LostGraceSoundPlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+bb7da60b5012775aa478457e5929453396ec938a")]
[assembly: AssemblyProduct("Lost Grace Campfire Sound")]
[assembly: AssemblyTitle("LostGraceSoundPlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.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 LostGraceSoundPlugin
{
[BepInPlugin("LostGraceSoundPlugin", "Lost Grace Campfire Sound", "1.1.0")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(Campfire), "Light_Rpc")]
private class Campfire_AddSound_Patch
{
private static void Prefix(Campfire __instance)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
string randomFile = SoundPlay.GetRandomFile(folderPath, Logger);
AudioType audioType = SoundPlay.GetAudioType(randomFile, Logger);
SoundPlay.PlaySound(randomFile, audioType, Logger, __instance);
}
}
private static string folderPath;
internal static ManualLogSource Logger;
private void Awake()
{
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin LostGraceSoundPlugin is loaded!");
List<string> list = Directory.GetDirectories(Paths.PluginPath, "lostgracesoundplugin", SearchOption.AllDirectories).ToList();
if (!list.Any())
{
Logger.LogError((object)"Couldn't find lostgracesoundplugin folder");
return;
}
folderPath = list[0];
Logger.LogDebug((object)(folderPath + " is the campfire sound path."));
Harmony val = new Harmony("com.egorvania1.lostgracesound.patch");
val.PatchAll();
}
}
public static class SoundPlay
{
public static string GetRandomFile(string soundsDir, ManualLogSource Logger)
{
string result = null;
if (!string.IsNullOrEmpty(soundsDir))
{
string[] extensions = new string[5] { ".mp3", ".aiff", ".aif", ".wav", ".ogg" };
try
{
DirectoryInfo directoryInfo = new DirectoryInfo(soundsDir);
IEnumerable<FileInfo> source = from f in directoryInfo.GetFiles("*.*")
where extensions.Contains(f.Extension.ToLower())
select f;
Random random = new Random();
result = source.ElementAt(random.Next(0, source.Count())).FullName;
}
catch (Exception arg)
{
Logger.LogError((object)$"Failed to load audio file. Full error: {arg}");
}
}
return result;
}
public static AudioType GetAudioType(string filePath, ManualLogSource Logger)
{
//IL_0002: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Unknown result type (might be due to invalid IL or missing references)
//IL_0063: Unknown result type (might be due to invalid IL or missing references)
//IL_0067: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
AudioType result = (AudioType)0;
if (!string.IsNullOrEmpty(filePath))
{
string extension = Path.GetExtension(filePath);
switch (extension)
{
case ".mp3":
result = (AudioType)13;
break;
case ".aiff":
case ".aif":
result = (AudioType)2;
break;
case ".wav":
result = (AudioType)20;
break;
case ".ogg":
result = (AudioType)14;
break;
default:
Logger.LogError((object)("Unknown file type: " + extension));
break;
}
}
return result;
}
public static void PlaySound(string filePath, AudioType fileType, ManualLogSource Logger, Campfire __instance)
{
//IL_0016: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Invalid comparison between Unknown and I4
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Invalid comparison between Unknown and I4
if (!Object.op_Implicit((Object)(object)__instance.loop) || string.IsNullOrEmpty(filePath) || (int)fileType <= 0)
{
return;
}
AudioClip val = null;
UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip("file:///" + filePath, fileType);
try
{
audioClip.SendWebRequest();
try
{
while (!audioClip.isDone)
{
}
if ((int)audioClip.result != 1)
{
Logger.LogError((object)("Failed to load AudioClip. Full error: " + audioClip.error));
return;
}
val = DownloadHandlerAudioClip.GetContent(audioClip);
__instance.loop.PlayOneShot(val, 10f);
Logger.LogInfo((object)"Playing campfire sound");
}
catch (Exception ex)
{
Logger.LogError((object)(ex.Message + ", " + ex.StackTrace));
}
}
finally
{
((IDisposable)audioClip)?.Dispose();
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "LostGraceSoundPlugin";
public const string PLUGIN_NAME = "Lost Grace Campfire Sound";
public const string PLUGIN_VERSION = "1.1.0";
}
}