Decompiled source of TomatoSounds v2.2.0

Tomatobird.TomatoSounds.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TomatoSounds.Patches;
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("Tomatobird.TomatoSounds")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0+835a582a21c89696c250856f467ec8f12fbebd00")]
[assembly: AssemblyProduct("TomatoSounds")]
[assembly: AssemblyTitle("Tomatobird.TomatoSounds")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.0.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 TomatoSounds
{
	public class AudioType
	{
		public AudioClip clip;

		public bool isInsanity;

		public bool isAmbient;

		public int rarity;

		public Dictionary<string, int> specificRarities;

		public AudioType(AudioClip audioClip, bool isNormalAmbient, bool isInsanityAmbient, int rarityValue = 1, string specificRaritiesText = "")
		{
			clip = audioClip;
			isInsanity = isInsanityAmbient;
			isAmbient = isNormalAmbient;
			rarity = rarityValue;
			specificRarities = GetSpecificRarities(specificRaritiesText);
			base..ctor();
		}

		internal static Dictionary<string, int> GetSpecificRarities(string text)
		{
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			string[] array = text.Split(',');
			string[] array2 = array;
			foreach (string text2 in array2)
			{
				string[] array3 = text2.Trim().Split(':');
				if (array3.Length == 2)
				{
					dictionary.Add(array3[0].Trim().ToLower(), int.Parse(array3[1].Trim()));
				}
			}
			return dictionary;
		}
	}
	[BepInPlugin("Tomatobird.TomatoSounds", "TomatoSounds", "1.3.0")]
	public class TomatoSounds : BaseUnityPlugin
	{
		internal static AssetBundle? bundle;

		internal static List<AudioClip>? audioClips;

		internal static List<AudioType> audioTypes = new List<AudioType>();

		internal static List<string> levelAmbienceNames = new List<string>();

		internal static bool playerSpecificRarityAdjustment;

		internal static bool playerSpecificAdjustmentsDone = false;

		public static TomatoSounds Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			bundle = AssetBundle.LoadFromFile(((BaseUnityPlugin)Instance).Info.Location.TrimEnd("Tomatobird.TomatoSounds.dll".ToCharArray()) + "insanitysounds");
			if ((Object)(object)bundle != (Object)null)
			{
				audioClips = bundle.LoadAllAssets<AudioClip>().ToList();
				foreach (AudioClip audioClip in audioClips)
				{
					audioTypes.Add(new AudioType(audioClip, ((BaseUnityPlugin)this).Config.Bind<bool>("Sound: " + ((Object)audioClip).name, "IsNormalAmbient", false, "Should audio clip be added to normal ambient sound lists?").Value, ((BaseUnityPlugin)this).Config.Bind<bool>("Sound: " + ((Object)audioClip).name, "IsInsanityAmbient", true, "Should audio clip be added to isanity ambient sound lists?").Value, ((BaseUnityPlugin)this).Config.Bind<int>("Sound: " + ((Object)audioClip).name, "Rarity", 1, "Default rarity of the insanity ambient sound").Value, ((BaseUnityPlugin)this).Config.Bind<string>("Sound: " + ((Object)audioClip).name, "PlayerSpecificRarities", "", "Special rarity override for each playername. Matches lowercase string anywhere within the steam name. name:20,anothername:10").Value));
				}
				playerSpecificRarityAdjustment = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PlayerSpecificAmbientRarityAdjustments", true, "Should player specific insanity audio ajustments be applied?").Value;
				Patch();
				Logger.LogInfo((object)"Tomatobird.TomatoSounds v1.3.0 has loaded successfully!");
			}
			else
			{
				Logger.LogError((object)"Tomatobird.TomatoSounds v1.3.0 failed to load!");
			}
		}

		internal static void Patch()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Tomatobird.TomatoSounds");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll(typeof(InsanityAmbiencePatch));
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Tomatobird.TomatoSounds";

		public const string PLUGIN_NAME = "TomatoSounds";

		public const string PLUGIN_VERSION = "1.3.0";
	}
}
namespace TomatoSounds.Patches
{
	[HarmonyPatch(typeof(RoundManager))]
	internal class InsanityAmbiencePatch
	{
		[HarmonyPatch("GenerateNewFloor")]
		[HarmonyPostfix]
		private static void AddAudio()
		{
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Expected O, but got Unknown
			if (TomatoSounds.audioClips == null)
			{
				TomatoSounds.Logger.LogError((object)"Audioclips were null. Did something go wrong during installation? Skipping...");
				return;
			}
			LevelAmbienceLibrary currentLevelAmbience = SoundManager.Instance.currentLevelAmbience;
			if ((Object)(object)currentLevelAmbience == (Object)null)
			{
				TomatoSounds.Logger.LogWarning((object)"LevelAmbienceLibrary was null. Skipping...");
			}
			else if (!TomatoSounds.levelAmbienceNames.Contains(((Object)currentLevelAmbience).name))
			{
				if (TomatoSounds.playerSpecificRarityAdjustment && !TomatoSounds.playerSpecificAdjustmentsDone)
				{
					PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
					foreach (PlayerControllerB val in allPlayerScripts)
					{
						if ((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)(object)val)
						{
							continue;
						}
						string text = val.playerUsername.ToLower();
						foreach (AudioType audioType in TomatoSounds.audioTypes)
						{
							if (!audioType.isInsanity)
							{
								continue;
							}
							foreach (KeyValuePair<string, int> specificRarity in audioType.specificRarities)
							{
								if (!text.Contains(specificRarity.Key))
								{
									continue;
								}
								audioType.rarity = specificRarity.Value;
								break;
							}
						}
					}
					TomatoSounds.playerSpecificAdjustmentsDone = true;
				}
				TomatoSounds.Logger.LogDebug((object)"LevelAmbienceLibrary name was not found in internal list. Adding new ambient sounds...");
				TomatoSounds.levelAmbienceNames.Add(((Object)currentLevelAmbience).name);
				List<RandomAudioClip> list = currentLevelAmbience.insideAmbienceInsanity.ToList();
				List<AudioClip> list2 = currentLevelAmbience.insideAmbience.ToList();
				foreach (AudioType audioType2 in TomatoSounds.audioTypes)
				{
					if (audioType2.isInsanity)
					{
						RandomAudioClip val2 = new RandomAudioClip();
						val2.audioClip = audioType2.clip;
						val2.chance = audioType2.rarity;
						list.Add(val2);
					}
					if (audioType2.isAmbient)
					{
						list2.Add(audioType2.clip);
					}
				}
				currentLevelAmbience.insideAmbienceInsanity = list.ToArray();
				currentLevelAmbience.insideAmbience = list2.ToArray();
				TomatoSounds.Logger.LogDebug((object)"New ambient sounds added!");
			}
			else
			{
				TomatoSounds.Logger.LogDebug((object)"LevelAmbienceLibrary name was found in internal list. Skipping...");
			}
		}
	}
}