Decompiled source of murica airhorn v1.0.0

plugins/AirHornSounds.dll

Decompiled 10 months ago
using System;
using System.Collections;
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 AirHornSounds.HelpfulBits;
using AirHornSounds.Patches;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[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("AirHornSounds")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AirHornSounds")]
[assembly: AssemblyTitle("AirHornSounds")]
[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 AirHornSounds
{
	public class AudioLoader
	{
		public static List<AudioClip> HornSounds = new List<AudioClip>();

		public static List<AudioClip> HornSoundsFar = new List<AudioClip>();

		private static string HornRoot = Path.Combine(Paths.PluginPath, "AirHornSounds");

		private static string HornFar = Path.Combine(Paths.PluginPath, "AirHornSounds", "Far");

		private static bool FirstRun = true;

		public static void Load()
		{
			if (!FirstRun)
			{
				return;
			}
			FirstRun = false;
			if (!Directory.Exists(HornRoot))
			{
				Plugin.LogWarning(HornRoot + " directory not found, changing to modmanager directory.");
				HornRoot = Path.Combine(Paths.PluginPath, "Oni_Hazza-Silly_Airhorn", "AirHornSounds");
				HornFar = Path.Combine(HornRoot, "Far");
			}
			string[] files = Directory.GetFiles(HornRoot);
			if (files.Length == 0 || files.Length == 1)
			{
				files = Directory.GetFiles(HornRoot);
				if (files.Length == 0 || files.Length == 1)
				{
					Plugin.LogError("No files have been found.");
					return;
				}
			}
			try
			{
				int num = 0;
				string[] array = files;
				foreach (string filePath in array)
				{
					SharedCoroutineStarter.StartCoroutine(LoadAudioClip(filePath, num, close: true));
					num++;
				}
				string[] files2 = Directory.GetFiles(HornFar);
				string[] array2 = files2;
				foreach (string filePath2 in array2)
				{
					SharedCoroutineStarter.StartCoroutine(LoadAudioClip(filePath2, num, close: false));
				}
			}
			catch (Exception ex)
			{
				Plugin.LogError(ex);
				Plugin.LogError("error in load method");
			}
		}

		private static IEnumerator LoadAudioClip(string filePath, int index, bool close)
		{
			Plugin.LogInfo("Loading " + filePath);
			UnityWebRequest loader = UnityWebRequestMultimedia.GetAudioClip(filePath, (AudioType)20);
			loader.SendWebRequest();
			while (!loader.isDone)
			{
				yield return null;
			}
			if (loader.error != null)
			{
				Plugin.LogError("Error Loading " + filePath + "\n" + loader.error);
				yield break;
			}
			AudioClip clip = DownloadHandlerAudioClip.GetContent(loader);
			if (Object.op_Implicit((Object)(object)clip) && (int)clip.loadState == 2)
			{
				((Object)clip).name = Path.GetFileName(filePath);
				if (close)
				{
					HornSounds.Add(clip);
				}
				else
				{
					HornSoundsFar.Add(clip);
				}
			}
		}
	}
	[BepInPlugin("OniHazza.AirHornHomeMade", "Silly_Airhorn", "1.0.0")]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "OniHazza.AirHornHomeMade";

		private const string modName = "Silly_Airhorn";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("OniHazza.AirHornHomeMade");

		private static Plugin Instance;

		private ConfigEntry<bool> IsEnabled;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			IsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General.Toggles", "Enabled", true, (ConfigDescription)null);
			if (IsEnabled.Value)
			{
				LogInfo("Plugin is loaded!");
				harmony.PatchAll(typeof(StartOfRoundPatch));
				harmony.PatchAll(typeof(AirHornPatch));
			}
			else
			{
				LogInfo("Plugin is disabled.");
			}
		}

		public static void LogInfo(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)16, (object)message);
		}

		public static void LogWarning(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)4, (object)message);
		}

		public static void LogError(string message)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)2, (object)message);
		}

		public static void LogError(Exception ex)
		{
			((BaseUnityPlugin)Instance).Logger.Log((LogLevel)2, (object)ex);
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "AirHornSounds";

		public const string PLUGIN_NAME = "AirHornSounds";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace AirHornSounds.Patches
{
	[HarmonyPatch(typeof(NoisemakerProp))]
	public class AirHornPatch
	{
		private static Random Rand = new Random();

		[HarmonyPatch("ItemActivate")]
		[HarmonyPrefix]
		private static void Prefix(NoisemakerProp __instance, bool used, bool buttonDown = true)
		{
			if (((GrabbableObject)__instance).itemProperties.itemName.ToLower() == "airhorn")
			{
				int index = Rand.Next(AudioLoader.HornSounds.Count);
				try
				{
					__instance.noiseSFX[0] = AudioLoader.HornSounds.ElementAt(index);
					__instance.noiseSFXFar[0] = AudioLoader.HornSoundsFar.ElementAt(index);
				}
				catch (Exception ex)
				{
					Plugin.LogError(ex);
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public class StartOfRoundPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static void Prefix()
		{
			AudioLoader.Load();
		}
	}
}
namespace AirHornSounds.HelpfulBits
{
	internal class SharedCoroutineStarter : MonoBehaviour
	{
		private static SharedCoroutineStarter _instance;

		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_instance == (Object)null)
			{
				_instance = new GameObject("Shared Coroutine Starter").AddComponent<SharedCoroutineStarter>();
				Object.DontDestroyOnLoad((Object)(object)_instance);
			}
			return ((MonoBehaviour)_instance).StartCoroutine(routine);
		}
	}
}