using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
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: AssemblyTitle("Suitsounds")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Suitsounds")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("8a747039-f1a4-4b1e-82a3-9d386b427994")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.example.BM_Suits-ChangeUp", "BM_Suits ChangeUp", "1.0.0")]
public class DynamicSuitChangeSoundMod : BaseUnityPlugin
{
[HarmonyPatch(typeof(UnlockableSuit), "SwitchSuitForPlayer")]
public static class SwitchSuitForPlayerPatch
{
[HarmonyPostfix]
public static void Postfix(PlayerControllerB player, int suitID)
{
PlayCustomSoundForSuit(player, suitID);
}
private static void PlayCustomSoundForSuit(PlayerControllerB player, int suitID)
{
List<UnlockableItem> unlockables = StartOfRound.Instance.unlockablesList.unlockables;
if (suitID < 0 || suitID >= unlockables.Count)
{
logger.LogWarning((object)$"Invalid suitID: {suitID}. Cannot play sound.");
return;
}
string unlockableName = unlockables[suitID].unlockableName;
if (string.IsNullOrEmpty(unlockableName))
{
logger.LogWarning((object)$"Suit name is null or empty for suitID: {suitID}");
return;
}
if (!suitSoundPaths.TryGetValue(unlockableName, out var value))
{
logger.LogWarning((object)("No custom sound defined for suit: " + unlockableName));
return;
}
if (!File.Exists(value))
{
logger.LogError((object)("Sound file not found at path: " + value));
return;
}
AudioClip val = LoadAudioClip(value);
if ((Object)(object)val == (Object)null)
{
logger.LogError((object)("Failed to load audio clip for suit: " + unlockableName));
return;
}
player.movementAudio.PlayOneShot(val);
logger.LogInfo((object)("Played custom sound for suit: " + unlockableName));
}
private static AudioClip LoadAudioClip(string path)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Invalid comparison between Unknown and I4
UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip("file://" + path, (AudioType)14);
try
{
UnityWebRequestAsyncOperation val = audioClip.SendWebRequest();
while (!((AsyncOperation)val).isDone)
{
}
if ((int)audioClip.result == 1)
{
return DownloadHandlerAudioClip.GetContent(audioClip);
}
logger.LogError((object)("Error loading audio clip: " + audioClip.error));
return null;
}
finally
{
((IDisposable)audioClip)?.Dispose();
}
}
}
private static ManualLogSource logger;
private static Dictionary<string, string> suitSoundPaths = new Dictionary<string, string>();
public void Awake()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
logger = ((BaseUnityPlugin)this).Logger;
Harmony val = new Harmony("com.example.BM_Suits-ChangeUp");
val.PatchAll();
LoadSuitSounds();
}
private static void LoadSuitSounds()
{
string text = Path.Combine(Paths.PluginPath, "Brox-BM_Suits/sounds");
if (!Directory.Exists(text))
{
Directory.CreateDirectory(text);
logger.LogWarning((object)("Sound directory not found. Created at: " + text));
return;
}
string[] files = Directory.GetFiles(text, "*_SuitUp.ogg");
string[] array = files;
foreach (string text2 in array)
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text2);
string text3 = fileNameWithoutExtension.Replace("_SuitUp", "");
suitSoundPaths[text3] = text2;
logger.LogInfo((object)("Loaded sound for suit: " + text3 + " from " + text2));
}
}
}