Decompiled source of RepoBomboclat v0.1.2

RepoBomboclat.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JetBrains.Annotations;
using Microsoft.CodeAnalysis;
using RepoBomboclat.Audio;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RepoBomboclat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2+9ab6ba158e3b399fbaa37244b7d5198bc019c7de")]
[assembly: AssemblyProduct("RepoBomboclat")]
[assembly: AssemblyTitle("RepoBomboclat")]
[assembly: AssemblyVersion("0.1.2.0")]
[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 RepoBomboclat
{
	public class ExtractPointBomboclat : MonoBehaviour
	{
		private ExtractionPoint _extractionPoint;

		private Sound _bomboclatSound;

		private bool _played;

		private FieldInfo _haulSurplusField;

		private FieldInfo _currentStateField;

		private FieldInfo _extractionPointsCompletedField;

		private FieldInfo _extractionPointsField;

		private void Start()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			_extractionPoint = ((Component)this).GetComponent<ExtractionPoint>();
			Sound val = new Sound();
			val.Sounds = (AudioClip[])(object)new AudioClip[1] { RepoBomboclat.BomboclatClip };
			_bomboclatSound = val;
			_haulSurplusField = AccessTools.Field(typeof(ExtractionPoint), "haulSurplus");
			_currentStateField = AccessTools.Field(typeof(ExtractionPoint), "currentState");
			_extractionPointsCompletedField = AccessTools.Field(typeof(RoundDirector), "extractionPointsCompleted");
			_extractionPointsField = AccessTools.Field(typeof(RoundDirector), "extractionPoints");
		}

		private void Update()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Invalid comparison between Unknown and I4
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Invalid comparison between Unknown and I4
			State val = (State)_currentStateField.GetValue(_extractionPoint);
			if (_played && (int)val == 5)
			{
				RepoBomboclat.Logger.LogInfo((object)"Extraction point is cancel, stop bomboclat");
				_played = false;
				_bomboclatSound.Stop();
			}
			if ((int)val != 8 || _played)
			{
				return;
			}
			int num = (int)_haulSurplusField.GetValue(_extractionPoint);
			if (RepoBomboclat.SurplusQuota.Value > 0f && (float)num < RepoBomboclat.SurplusQuota.Value)
			{
				return;
			}
			RepoBomboclat.Logger.LogInfo((object)("EP surplus is: " + num));
			if (RepoBomboclat.OnlyOnLastExtract.Value)
			{
				int num2 = (int)_extractionPointsCompletedField.GetValue(_extractionPoint);
				int num3 = (int)_extractionPointsField.GetValue(_extractionPoint);
				if (num2 == num3 - 1)
				{
					RepoBomboclat.Logger.LogInfo((object)"Last extraction point at surplus, playing bomboclat");
					PlaySound();
				}
			}
			else
			{
				RepoBomboclat.Logger.LogInfo((object)"Extraction point at surplus, playing bomboclat");
				PlaySound();
			}
		}

		private void PlaySound()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			_played = true;
			_bomboclatSound.Source = _bomboclatSound.Play(((Component)_extractionPoint).transform.position, 1f, 1f, 1f, 1f);
		}
	}
	[BepInPlugin("RepoBomboclat", "RepoBomboclat", "0.1.2")]
	public class RepoBomboclat : BaseUnityPlugin
	{
		public static RepoBomboclat Instance;

		private static Harmony _harmony;

		internal static AudioClip BomboclatClip;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> OnlyOnLastExtract;

		internal static ConfigEntry<float> SurplusQuota;

		public static ManualLogSource Logger { get; set; }

		private void Awake()
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			Logger = Logger.CreateLogSource("RepoBomboclat");
			Instance = this;
			Logger.LogInfo((object)"Plugin RepoBomboclat is loaded!");
			GenerateConfig();
			if (Enabled.Value)
			{
				if (_harmony == null)
				{
					_harmony = new Harmony("RepoBomboclat");
				}
				_harmony.PatchAll();
				BomboclatClip = AudioClipLoader.Load(ExtractEmbeddedAudio("RepoBomboclat.bomboclat.mp3"));
			}
		}

		private void GenerateConfig()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("", "Enabled", true, "Enables trigger sound");
			OnlyOnLastExtract = ((BaseUnityPlugin)this).Config.Bind<bool>("Trigger Options", "Only On Last Extract", false, new ConfigDescription("Trigger sound only at last extract point | Default False", (AcceptableValueBase)null, Array.Empty<object>()));
			SurplusQuota = ((BaseUnityPlugin)this).Config.Bind<float>("Trigger Options", "Surplus Quota", 10000f, new ConfigDescription("The surplus value after which trigger sound | Default 10k", (AcceptableValueBase)null, Array.Empty<object>()));
		}

		[CanBeNull]
		private string ExtractEmbeddedAudio(string resourceName)
		{
			if (string.IsNullOrEmpty(resourceName))
			{
				Logger.LogError((object)"Resource name is null or empty.");
				return null;
			}
			string text = Path.Combine(Application.temporaryCachePath, resourceName);
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
			using FileStream destination = File.Open(text, FileMode.OpenOrCreate, FileAccess.Write);
			if (stream == null)
			{
				Logger.LogError((object)("Failed to find resource: " + resourceName));
				return null;
			}
			stream.CopyTo(destination);
			return text;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "RepoBomboclat";

		public const string PLUGIN_NAME = "RepoBomboclat";

		public const string PLUGIN_VERSION = "0.1.2";
	}
}
namespace RepoBomboclat.Patches
{
	[HarmonyPatch]
	public class ExtractPointPatch
	{
		[HarmonyPatch(typeof(ExtractionPoint), "Start")]
		[HarmonyPostfix]
		public static void StartPostfix(ExtractionPoint __instance)
		{
			((Component)__instance).gameObject.AddComponent<ExtractPointBomboclat>();
		}
	}
}
namespace RepoBomboclat.Audio
{
	public static class AudioClipLoader
	{
		[CanBeNull]
		public static AudioClip Load(string path)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			string fileName = Path.GetFileName(path);
			string extension = Path.GetExtension(path);
			if (string.IsNullOrEmpty(extension))
			{
				RepoBomboclat.Logger.LogError((object)("The path " + path + " is invalid."));
				return null;
			}
			AudioType val = (AudioType)(extension switch
			{
				".wav" => 20, 
				".ogg" => 14, 
				".mp3" => 13, 
				_ => 0, 
			});
			if ((int)val == 0)
			{
				RepoBomboclat.Logger.LogError((object)(fileName + " not loaded, because it is an unknown audio type."));
				return null;
			}
			return Load(path, val);
		}

		[CanBeNull]
		public static AudioClip Load(string path, AudioType type)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(path, type);
			try
			{
				audioClip.SendWebRequest();
				try
				{
					while (!audioClip.isDone)
					{
					}
					if ((int)audioClip.result != 1)
					{
						RepoBomboclat.Logger.LogError((object)("Failed to load AudioClip from path: " + path + " Full error: " + audioClip.error));
						return null;
					}
					return DownloadHandlerAudioClip.GetContent(audioClip);
				}
				catch (Exception ex)
				{
					RepoBomboclat.Logger.LogError((object)(ex.Message + ", " + ex.StackTrace));
					return null;
				}
			}
			finally
			{
				((IDisposable)audioClip)?.Dispose();
			}
		}
	}
}