Decompiled source of YoutubeBoomboxVolumeConfig v1.0.0

BepInEx/plugins/YoutubeBoomboxVolumeConfig.dll

Decompiled 10 months ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("YoutubeBoomboxVolumeConfig")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("YoutubeBoomboxVolumeConfig")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("3b24fd98-00c9-4e13-badc-8a703e51cc65")]
[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")]
namespace YoutubeBoomboxVolumeConfig;

internal class YoutubeBoomboxVolumeConfigConfig
{
	public static ConfigEntry<float> Volume;

	public static void InitConfig()
	{
		ModManager.Instance.BindConfig(ref Volume, "Volume Settings", "Preferred Volume", 25f, "Whenever a boombox is played, all boomboxes in scene will have their volumes adjusted to the preferred volume value. If a boombox's volume is manually changed, the preferred volume value will be overridden.");
	}
}
[BepInPlugin("zMods.YoutubeBoomboxVolumeConfig", "YoutubeBoomboxVolumeConfig", "1.0.0")]
public class ModManager : BaseUnityPlugin
{
	private const string modGUID = "zMods.YoutubeBoomboxVolumeConfig";

	private const string modName = "YoutubeBoomboxVolumeConfig";

	private const string modVersion = "1.0.0";

	private readonly Harmony harmony = new Harmony("zMods.YoutubeBoomboxVolumeConfig");

	public static ModManager Instance;

	internal ManualLogSource mls;

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = this;
		}
		mls = Logger.CreateLogSource("zMods.YoutubeBoomboxVolumeConfig");
		mls.LogInfo((object)"zMods.YoutubeBoomboxVolumeConfig: Awake()");
		harmony.PatchAll(typeof(ModManager));
		harmony.PatchAll(typeof(ChangeBoomboxVolumeClass));
		YoutubeBoomboxVolumeConfigConfig.InitConfig();
	}

	public void BindConfig<T>(ref ConfigEntry<T> config, string section, string key, T defaultValue, string description = "")
	{
		config = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, defaultValue, description);
	}
}
internal class ChangeBoomboxVolumeClass
{
	private static List<BoomboxItem> ModifiedBoomboxes = new List<BoomboxItem>();

	public static float Volume;

	private static bool HasReadConfig;

	[HarmonyPatch(typeof(BoomboxItem), "StartMusic")]
	[HarmonyPrefix]
	private static void ChangeBoomboxVolume()
	{
		if (!HasReadConfig)
		{
			HasReadConfig = true;
			Volume = YoutubeBoomboxVolumeConfigConfig.Volume.Value;
		}
		BoomboxItem[] array = Object.FindObjectsOfType<BoomboxItem>();
		BoomboxItem[] array2 = array;
		foreach (BoomboxItem val in array2)
		{
			if (ModifiedBoomboxes.Contains(val))
			{
				Volume = val.boomboxAudio.volume * 100f;
			}
		}
		BoomboxItem[] array3 = array;
		foreach (BoomboxItem val2 in array3)
		{
			val2.boomboxAudio.volume = Volume / 100f;
			if (!ModifiedBoomboxes.Contains(val2))
			{
				ModifiedBoomboxes.Add(val2);
			}
		}
	}
}