Decompiled source of CustomRadarSounds v1.0.2

BepInEx/plugins/CustomRadarSounds/CustomRadarSounds.dll

Decompiled a year ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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("CustomRadarSounds")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CustomRadarSounds")]
[assembly: AssemblyTitle("CustomRadarSounds")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomRadarSounds
{
	public class HarmonyPatches
	{
		private static Harmony instance;

		public const string InstanceId = "com.graze.gorillatag.customradarsounds";

		public static bool IsPatched { get; private set; }

		internal static void ApplyHarmonyPatches()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			if (!IsPatched)
			{
				if (instance == null)
				{
					instance = new Harmony("com.graze.gorillatag.customradarsounds");
				}
				instance.PatchAll(Assembly.GetExecutingAssembly());
				IsPatched = true;
			}
		}

		internal static void RemoveHarmonyPatches()
		{
			if (instance != null && IsPatched)
			{
				instance.UnpatchSelf();
				IsPatched = false;
			}
		}
	}
	[BepInPlugin("com.graze.gorillatag.customradarsounds", "CustomRadarSounds", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static ConfigEntry<int> Audio;

		private Plugin()
		{
			Begin();
		}

		private void Begin()
		{
			HarmonyPatches.ApplyHarmonyPatches();
			Audio = ((BaseUnityPlugin)this).Config.Bind<int>("Settings", "AudioClip", 0, "Pick what number clip you would like to use (Rejoin a lobby to apply)");
		}
	}
	public class AudioThing : MonoBehaviour
	{
		public static AudioThing thing;

		private string AudioPath = Path.Combine(Paths.PluginPath, "CustomRadarSounds".ToString(), "Audio");

		private List<string> audioNames = new List<string>();

		private AudioClip audio;

		public void Getaudio()
		{
			if (!Directory.Exists(AudioPath))
			{
				Directory.CreateDirectory(AudioPath);
			}
			string[] files = Directory.GetFiles(AudioPath);
			string[] array = new string[files.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Path.GetFileName(files[i]);
				audioNames.Add(array[i]);
			}
			((MonoBehaviour)this).StartCoroutine(LoadAudioCoroutine());
		}

		private IEnumerator LoadAudioCoroutine()
		{
			UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(Path.Combine(AudioPath, audioNames[Plugin.Audio.Value]), (AudioType)0);
			try
			{
				yield return www.SendWebRequest();
				if ((int)www.result == 1)
				{
					AudioClip audioClip = DownloadHandlerAudioClip.GetContent(www);
					audio = audioClip;
				}
				else
				{
					Debug.LogError((object)("Failed to load audio: " + www.error));
				}
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
		}

		private void Update()
		{
			if ((Object)(object)audio != (Object)null)
			{
				HUDManager.Instance.scanSFX = audio;
				Object.Destroy((Object)(object)this);
			}
		}
	}
	internal class PluginInfo
	{
		public const string GUID = "com.graze.gorillatag.customradarsounds";

		public const string Name = "CustomRadarSounds";

		public const string Version = "1.0.0";
	}
}
namespace CustomRadarSounds.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class AudioPatch
	{
		private static void Postfix(HUDManager __instance)
		{
			AudioThing.thing = ((Component)__instance).gameObject.AddComponent<AudioThing>();
			AudioThing.thing.Getaudio();
		}
	}
}