Decompiled source of CaveSoundsBeGone v0.0.1

CaveSoundsBeGone.dll

Decompiled 11 months ago
using System;
using System.Diagnostics;
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 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: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("CaveSoundsBeGone")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CaveSoundsBeGone")]
[assembly: AssemblyTitle("CaveSoundsBeGone")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace CaveSoundsBeGone;

[BepInPlugin("CaveSoundsBeGone", "CaveSoundsBeGone", "1.0.0")]
public class CaveSoundsBeGonePlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(AudioMan), "QueueAmbientLoop")]
	public class AudioMan_QueueAmbientLoop_Patch
	{
		public static void Prefix(AudioClip clip, ref float vol)
		{
			if (enableMod.Value && doEerieOverride.Value && ((Object)clip).name == "Amb_Eerie_GraveIntLoop")
			{
				vol = (float)eerieVol.Value / 100f;
			}
		}
	}

	[HarmonyPatch]
	public class AudioMan_UpdateWindAmbience_Patch
	{
		private static MethodBase TargetMethod()
		{
			return typeof(AudioMan).GetMethod("UpdateWindAmbience", BindingFlags.Instance | BindingFlags.NonPublic);
		}

		public static void Postfix(AudioMan __instance, float dt)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			if (enableMod.Value && doWindOverride.Value)
			{
				AudioSource val = (AudioSource)typeof(AudioMan).GetField("m_windLoopSource", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
				val.volume = Mathf.Lerp(val.volume, (float)windVol.Value / 100f, volumeFade);
			}
		}
	}

	[HarmonyPatch]
	public class AudioMan_UpdateOceanAmbiance_Patch
	{
		private static MethodBase TargetMethod()
		{
			return typeof(AudioMan).GetMethod("UpdateOceanAmbiance", BindingFlags.Instance | BindingFlags.NonPublic);
		}

		public static void Postfix(AudioMan __instance)
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			if (enableMod.Value && doOceanOverride.Value)
			{
				AudioSource val = (AudioSource)typeof(AudioMan).GetField("m_oceanAmbientSource", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(__instance);
				val.volume = Mathf.Lerp(val.volume, (float)oceanVol.Value / 100f, volumeFade);
			}
		}
	}

	[HarmonyPatch]
	public class AudioMan_SelectRandomAmbientClip_Patch
	{
		private static MethodBase TargetMethod()
		{
			return typeof(AudioMan).GetMethod("SelectRandomAmbientClip", BindingFlags.Instance | BindingFlags.NonPublic);
		}

		public static bool Prefix(ref bool __result)
		{
			if (!enableMod.Value || !disableRandomSounds.Value)
			{
				return true;
			}
			if ((Object)(object)EnvMan.instance != (Object)null && EnvMan.instance.GetCurrentEnvironment().m_name == "Crypt")
			{
				__result = false;
				return false;
			}
			return true;
		}
	}

	public static ConfigEntry<bool> enableMod;

	public static ConfigEntry<bool> doWindOverride;

	public static ConfigEntry<int> windVol;

	public static ConfigEntry<bool> doOceanOverride;

	public static ConfigEntry<int> oceanVol;

	public static ConfigEntry<bool> doEerieOverride;

	public static ConfigEntry<int> eerieVol;

	public static ConfigEntry<bool> disableRandomSounds;

	public static float volumeFade = 0f;

	public static bool volumeFadeUp = true;

	private static ManualLogSource logger;

	private void Awake()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Expected O, but got Unknown
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Expected O, but got Unknown
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Expected O, but got Unknown
		logger = ((BaseUnityPlugin)this).Logger;
		enableMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableMod", true, "Enable the mod?");
		doWindOverride = ((BaseUnityPlugin)this).Config.Bind<bool>("Volume Controls", "WindSoundOverride", true, "Override wind volume in caves (0-100%)");
		windVol = ((BaseUnityPlugin)this).Config.Bind<int>("Volume Controls", "WindVolumePercentage", 0, new ConfigDescription("New wind volume", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		doOceanOverride = ((BaseUnityPlugin)this).Config.Bind<bool>("Volume Controls", "OceanSoundOverride", true, "Override ocean volume in caves (0-100%)");
		oceanVol = ((BaseUnityPlugin)this).Config.Bind<int>("Volume Controls", "OceanVolumePercentage", 0, new ConfigDescription("New ocean volume", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		doEerieOverride = ((BaseUnityPlugin)this).Config.Bind<bool>("Volume Controls", "EerieSoundOverride", true, "Override ghost-like eerie ambience volume in caves (0-100%)");
		eerieVol = ((BaseUnityPlugin)this).Config.Bind<int>("Volume Controls", "EerieVolumePercentage", 0, new ConfigDescription("Override ghost-like eerie ambience volume in caves", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		disableRandomSounds = ((BaseUnityPlugin)this).Config.Bind<bool>("Volume Controls", "DisableRandomSounds", true, "Disable random 3d sounds in caves");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin CaveSoundsBeGone is loaded!");
		Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
	}

	private void Update()
	{
		if ((Object)(object)EnvMan.instance != (Object)null && EnvMan.instance.GetCurrentEnvironment().m_name == "Crypt")
		{
			volumeFadeUp = true;
		}
		else
		{
			volumeFadeUp = false;
		}
		if (volumeFadeUp && volumeFade < 1f)
		{
			volumeFade += Time.deltaTime / 4f;
		}
		else if (!volumeFadeUp && volumeFade > 0f)
		{
			volumeFade -= Time.deltaTime / 5f;
		}
		volumeFade = Mathf.Clamp(volumeFade, 0f, 1f);
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "CaveSoundsBeGone";

	public const string PLUGIN_NAME = "CaveSoundsBeGone";

	public const string PLUGIN_VERSION = "1.0.0";
}