Decompiled source of BoomboxVolumeAdjuster v1.0.1

plugins/BoomboxVolumeAdjuster.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BoomboxVolumeAdjuster.Patches;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("YveX")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A mod that lets you adjust the volume of the boombox")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+76238b5c60808937151b2877ffdda960b8d0968e")]
[assembly: AssemblyProduct("BoomboxVolumeAdjuster")]
[assembly: AssemblyTitle("BoomboxVolumeAdjuster")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 BoomboxVolumeAdjuster
{
	[BepInPlugin("BoomboxVolumeAdjuster", "BoomboxVolumeAdjuster", "1.0.1")]
	public class BoomboxVolumeAdjusterPlugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("BoomboxVolumeAdjuster");

		public static BoomboxVolumeAdjusterPlugin Instance { get; private set; }

		public ManualLogSource ModLogger => ((BaseUnityPlugin)this).Logger;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin BoomboxVolumeAdjuster is loaded!");
			Config.Init();
			_harmony.PatchAll(typeof(BoomboxVolumeAdjusterPlugin));
			_harmony.PatchAll(typeof(BoomboxVolumePatch));
		}

		internal static void LogInfo(string message)
		{
			Instance.ModLogger.LogInfo((object)message);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BoomboxVolumeAdjuster";

		public const string PLUGIN_NAME = "BoomboxVolumeAdjuster";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}
namespace BoomboxVolumeAdjuster.Patches
{
	[HarmonyPatch(typeof(BoomboxItem))]
	internal class BoomboxVolumePatch
	{
		[HarmonyPatch("StartMusic")]
		[HarmonyPrefix]
		private static void StartMusic(bool startMusic, ref AudioSource ___boomboxAudio)
		{
			if (startMusic)
			{
				BoomboxVolumeAdjusterPlugin.LogInfo($"Volume: {Config.BoomboxVolume * 100f}");
				___boomboxAudio.volume = Config.BoomboxVolume;
			}
		}
	}
	internal class Config
	{
		private const string CONFIG_FILE_NAME = "yvex.boomboxVolumeAdjuster.cfg";

		private static ConfigFile _config;

		private static ConfigEntry<bool> _dontUpdateAfterStart;

		private static ConfigEntry<float> _boomboxVolume;

		public static bool DontUpdateAfterStart => _dontUpdateAfterStart != null && _dontUpdateAfterStart.Value;

		public static float BoomboxVolume
		{
			get
			{
				if (!DontUpdateAfterStart)
				{
					BoomboxVolumeAdjusterPlugin.LogInfo("Reloading volume...");
					_config.Reload();
					ReadVolume();
				}
				return (_boomboxVolume != null) ? (Math.Clamp(_boomboxVolume.Value, 0f, 100f) / 100f) : 1f;
			}
		}

		private static void ReadDontUpdateAfterStart()
		{
			_dontUpdateAfterStart = _config.Bind<bool>("Config", "Dont Update After Start", false, "If you are happy with the current volume you should set this to true for performance reasons\n (Avoids boombox volume update after launch)");
		}

		private static void ReadVolume()
		{
			_boomboxVolume = _config.Bind<float>("Config", "Boombox Volume", 100f, "Set a value in range [0 - 100]");
		}

		public static void Init()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			BoomboxVolumeAdjusterPlugin.LogInfo("Initializing config...");
			_config = new ConfigFile(Path.Combine(Paths.ConfigPath, "yvex.boomboxVolumeAdjuster.cfg"), true);
			ReadDontUpdateAfterStart();
			ReadVolume();
			BoomboxVolumeAdjusterPlugin.LogInfo("Config initialized!");
		}

		private static void PrintConfig()
		{
			BoomboxVolumeAdjusterPlugin.LogInfo($"Dont update after start: {_dontUpdateAfterStart}");
			BoomboxVolumeAdjusterPlugin.LogInfo($"Boombox volume: {_boomboxVolume}");
		}
	}
}