Decompiled source of BM Suits v0.2.1

ChangeUp.dll

Decompiled 2 weeks ago
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));
		}
	}
}

JumpSound.dll

Decompiled 2 weeks ago
using System;
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 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.brox.BM_Suits", "BM_Suits", "1.0.0")]
public class CustomAudioPatch : BaseUnityPlugin
{
	[HarmonyPatch(typeof(StartOfRound), "Start")]
	public static class StartOfRoundPatch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			AssignJumpAudioToSuit();
		}
	}

	private static ManualLogSource logger;

	public void Awake()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Expected O, but got Unknown
		logger = ((BaseUnityPlugin)this).Logger;
		logger.LogInfo((object)"BM_Suits mod is initializing...");
		logger.LogInfo((object)"BM_Suits plugin loaded successfully!");
		Harmony val = new Harmony("com.brox.BM_Suits");
		val.PatchAll();
	}

	public static void AssignJumpAudioToSuit()
	{
		if ((Object)(object)StartOfRound.Instance?.unlockablesList == (Object)null)
		{
			logger.LogError((object)"Unlockables list is null. Cannot assign jump audio.");
			return;
		}
		foreach (UnlockableItem unlockable in StartOfRound.Instance.unlockablesList.unlockables)
		{
			if (unlockable == null || string.IsNullOrEmpty(unlockable.unlockableName))
			{
				continue;
			}
			string text = Path.Combine(Paths.PluginPath, "Brox-BM_Suits/sounds", unlockable.unlockableName + "_Jump.ogg");
			if (File.Exists(text))
			{
				AudioClip val = LoadAudioClipFromPath(text);
				if ((Object)(object)val != (Object)null)
				{
					unlockable.jumpAudio = val;
					logger.LogInfo((object)("Assigned custom jump audio for " + unlockable.unlockableName + " suit."));
				}
				else
				{
					logger.LogWarning((object)("Failed to load jump audio clip for " + unlockable.unlockableName + " suit."));
				}
			}
			else
			{
				logger.LogWarning((object)("Jump audio file not found for " + unlockable.unlockableName + " at path: " + text));
			}
		}
	}

	private static AudioClip LoadAudioClipFromPath(string path)
	{
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Invalid comparison between Unknown and I4
		logger.LogInfo((object)("Attempting to load audio clip from: " + path));
		UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip("file://" + path, (AudioType)14);
		try
		{
			UnityWebRequestAsyncOperation val = audioClip.SendWebRequest();
			while (!((AsyncOperation)val).isDone)
			{
			}
			if ((int)audioClip.result == 1)
			{
				AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
				logger.LogInfo((object)("Audio clip loaded successfully: " + ((content != null) ? ((Object)content).name : null)));
				return content;
			}
			logger.LogError((object)("Failed to load audio clip from: " + path + ". Error: " + audioClip.error));
			return null;
		}
		finally
		{
			((IDisposable)audioClip)?.Dispose();
		}
	}
}