Decompiled source of BendyMenuMusicChange v1.0.3

BMMC.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("BMMC")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("BMMC")]
[assembly: AssemblyTitle("BMMC")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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 BMMC
{
	[BepInPlugin("BMMC", "BMMC", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Logger;

		internal static bool playCustom;

		private void Awake()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin loaded!");
			new Harmony("com.cosita3cz.BMMC").PatchAll();
		}
	}
	[HarmonyPatch]
	public class S13AudioManagerPatch
	{
		private static MethodBase TargetMethod()
		{
			Type type = Type.GetType("S13Audio.S13AudioManager, Assembly-CSharp");
			if ((object)type == null)
			{
				Plugin.Logger.LogError((object)"Failed to resolve S13AudioManager type.");
				return null;
			}
			MethodInfo? method = type.GetMethod("InvokeEvent", BindingFlags.Instance | BindingFlags.Public);
			if ((object)method == null)
			{
				Plugin.Logger.LogError((object)"Failed to resolve InvokeEvent method on S13AudioManager.");
			}
			return method;
		}

		private static void Prefix(string eventName)
		{
			if (eventName == "evt_game_at_main_menu")
			{
				Plugin.Logger.LogInfo((object)"Main menu event triggered");
				ReplaceMenuMusic();
			}
		}

		private static void ReplaceMenuMusic()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			Plugin.Logger.LogInfo((object)"Replacing menu music");
			AudioSource val = Object.FindObjectOfType<AudioSource>();
			if ((Object)(object)val != (Object)null)
			{
				val.Stop();
				using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("BMMC.assets.menu_music.ogg"))
				{
					if (stream != null)
					{
						byte[] array = new byte[stream.Length];
						stream.Read(array, 0, array.Length);
						string text = Path.Combine(Application.temporaryCachePath, "menu_music.ogg");
						File.WriteAllBytes(text, array);
						WWW val2 = new WWW("file://" + text);
						while (!val2.isDone)
						{
						}
						if (string.IsNullOrEmpty(val2.error))
						{
							val.clip = val2.GetAudioClip();
							Plugin.Logger.LogInfo((object)"Custom menu music loaded and ready to play.");
						}
						else
						{
							Plugin.Logger.LogError((object)("Failed to decode audio file: " + val2.error));
						}
					}
					else
					{
						Plugin.Logger.LogError((object)"Failed to load embedded resource: BMMC.assets.menu_music.mp3");
					}
				}
				val.Play();
				Plugin.Logger.LogInfo((object)"Custom menu music is now playing.");
			}
			else
			{
				Plugin.Logger.LogWarning((object)"No AudioSource found to replace menu music.");
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "BMMC";

		public const string PLUGIN_NAME = "BMMC";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}