using System;
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 System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ElevatorSymphony.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("ElevatorSymphony")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ElevatorSymphony")]
[assembly: AssemblyTitle("ElevatorSymphony")]
[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 ElevatorSymphony
{
[BepInPlugin("com.sk737.elevatorsymphony", "ElevatorSymphony", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal const string GUID = "com.sk737.elevatorsymphony";
internal const string NAME = "ElevatorSymphony";
internal const string VERSION = "1.0.0";
private string[] mClipFiles;
private Harmony mHarmony = new Harmony("com.sk737.elevatorsymphony");
internal static ManualLogSource LoggerInstance { get; private set; }
internal static Plugin Instance { get; private set; }
internal string ExecutingPath => Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
internal Random Random { get; set; }
public static Config Config { get; private set; }
private void Awake()
{
Config = new Config(((BaseUnityPlugin)this).Config);
Instance = this;
LoggerInstance = ((BaseUnityPlugin)this).Logger;
if (Directory.Exists(ExecutingPath + "/Music"))
{
mClipFiles = (from f in Directory.GetFiles(ExecutingPath + "/Music")
orderby f
select f).ToArray();
}
mHarmony.PatchAll(typeof(RoundManagerPatch));
mHarmony.PatchAll(typeof(StartStartOfRoundPatch));
mHarmony.PatchAll(typeof(Plugin));
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ElevatorSymphony is loaded!");
}
public AudioType GetAudioType(string extension)
{
return (AudioType)(extension switch
{
".mp3" => 13,
".wav" => 20,
_ => 14,
});
}
public async Task LoadClip(string path, Action<AudioClip> callback)
{
AudioType audioType = GetAudioType(Path.GetExtension(path));
UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(path, audioType);
try
{
request.SendWebRequest();
while (!request.isDone)
{
await Task.Delay(50);
}
if ((int)request.result != 1)
{
((BaseUnityPlugin)this).Logger.LogError((object)("Failed to load file:" + path + ", + " + request.error));
return;
}
AudioClip content = DownloadHandlerAudioClip.GetContent(request);
((BaseUnityPlugin)this).Logger.LogMessage((object)("Loaded file: " + path));
callback(content);
}
finally
{
if (request != null)
{
request.Dispose();
}
}
}
public void LoadNewAudioFile()
{
int num = Random.Next(Config.IncludeDefaultElevatorMusic.Value ? (-1) : 0, mClipFiles.Length);
if (num >= 0 && mClipFiles.Length != 0)
{
LoadClip(mClipFiles[num], SetElevator);
}
}
public void SetElevator(AudioClip clip)
{
MineshaftElevatorController val = Object.FindObjectOfType<MineshaftElevatorController>();
if ((Object)(object)val != (Object)null)
{
val.elevatorJingleMusic.clip = clip;
}
}
}
public class Config
{
public static ConfigEntry<bool> IncludeDefaultElevatorMusic;
public Config(ConfigFile config)
{
IncludeDefaultElevatorMusic = config.Bind<bool>("General", "IncludeDefaultElevatorMusic", true, "Allows the randomizer to pick the games elevator music");
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "ElevatorSymphony";
public const string PLUGIN_NAME = "ElevatorSymphony";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace ElevatorSymphony.Patches
{
[HarmonyPatch(typeof(RoundManager))]
internal class RoundManagerPatch
{
[HarmonyPatch("InitializeRandomNumberGenerators")]
[HarmonyPrefix]
public static void SeedPatch(ref RoundManager __instance)
{
Plugin.LoggerInstance.LogInfo((object)$"Initializing random with seed {__instance.playersManager.randomMapSeed}");
Plugin.Instance.Random = new Random(__instance.playersManager.randomMapSeed);
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartStartOfRoundPatch
{
[HarmonyPatch("openingDoorsSequence")]
[HarmonyPostfix]
public static void openingDoorsSequencePatch()
{
Plugin.Instance.LoadNewAudioFile();
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}