Decompiled source of CustomSoundsForFriends v1.1.0

CustomMemeSounds.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.Configuration;
using BepInEx.Logging;
using LCSoundTool;
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("CustomMemeSounds")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CustomMemeSounds")]
[assembly: AssemblyTitle("CustomMemeSounds")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MyFirstPlugin
{
	[BepInPlugin("ChiliTaco.CustomMemeSounds", "CustomMemeSounds", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "ChiliTaco.CustomMemeSounds";

		private const string modName = "CustomMemeSounds";

		private const string modVersion = "1.0.0";

		public static ConfigEntry<bool> EnableInfiniteSprint;

		public static ConfigEntry<bool> EnableCustomSounds;

		public static string soundsPath = Path.Combine(Paths.PluginPath, "ChiliTaco-CustomSoundsForFriends\\CustomSounds");

		public List<(string, AudioClip)> customSounds = new List<(string, AudioClip)>();

		private static Plugin Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("ChiliTaco.CustomMemeSounds");
			if (!Directory.Exists(soundsPath))
			{
				mls.LogDebug((object)"Creating sounds folder");
				Directory.CreateDirectory(soundsPath);
			}
			if (Directory.GetFiles(soundsPath, "*.wav").Length == 0)
			{
				mls.LogError((object)"No sound files detected! Searching for sound files in parent folder.");
				string[] files = Directory.GetFiles(Path.Combine(Paths.PluginPath, "ChiliTaco-CustomSoundsForFriends"), "*.wav");
				foreach (string text in files)
				{
					mls.LogDebug((object)"File found moving it.");
					File.Move(text, soundsPath + "\\" + text.Split("\\").Last());
				}
			}
			mls.LogInfo((object)"Plugin ChiliTaco.CustomMemeSounds is loaded!");
			SetBindings();
		}

		private void Start()
		{
			LoadAudios(soundsPath);
			ReplaceAudios();
			EnableCustomSounds.SettingChanged += delegate
			{
				if (EnableCustomSounds.Value)
				{
					ReplaceAudios();
				}
				else
				{
					ResetAudios();
				}
			};
			mls.LogInfo((object)"Loaded all the sounds successfully!");
		}

		private void SetBindings()
		{
			EnableCustomSounds = ((BaseUnityPlugin)this).Config.Bind<bool>("Host Settings", "Enable Custom sound effects", true, "If true custom sounds are enabled, if false all default audio's will be played.");
		}

		private void LoadAudios(string path)
		{
			string[] files = Directory.GetFiles(path, "*.wav");
			mls.LogDebug((object)("Loading Audios from " + path));
			string[] array = files;
			foreach (string text in array)
			{
				string text2 = text.Split("\\").Last().Split("-")[0];
				AudioClip audioClip = SoundTool.GetAudioClip(path, text.Split("\\").Last());
				mls.LogDebug((object)("Parsed Data: " + text2 + "--" + text));
				customSounds.Add((text2, audioClip));
			}
			mls.LogDebug((object)"Loaded all the files: ");
			foreach (var customSound in customSounds)
			{
				AudioClip item = customSound.Item2;
				mls.LogDebug((object)((object)item).ToString());
			}
		}

		private void ReplaceAudios()
		{
			foreach (var (text, val) in customSounds)
			{
				SoundTool.ReplaceAudioClip(text, val);
			}
			mls.LogDebug((object)$"Replaced Clips. Current count is {SoundTool.replacedClips.Count()}.");
			mls.LogDebug((object)$"Replaced clips: {SoundTool.replacedClips}");
		}

		private void ResetAudios()
		{
			foreach (var customSound in customSounds)
			{
				string item = customSound.Item1;
				SoundTool.RestoreAudioClip(item);
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "CustomMemeSounds";

		public const string PLUGIN_NAME = "CustomMemeSounds";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}