Decompiled source of BudylivRaidAlert v1.1.0

plugins/BudylivRaidAlert.dll

Decompiled 44 minutes ago
using System;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 BudylivRaidAlert
{
	[BepInPlugin("com.budyliv.raidalert", "Budyliv RaidAlert", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.budyliv.raidalert";

		public const string Name = "Budyliv RaidAlert";

		public const string Version = "1.1.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<string> Language;

		internal static ConfigEntry<bool> Banner;

		internal static ConfigEntry<float> BannerOffsetY;

		internal static ConfigEntry<float> BannerBlinkSeconds;

		internal static ConfigEntry<bool> EdgeFlash;

		internal static ConfigEntry<float> EdgeFlashSeconds;

		internal static ConfigEntry<bool> OtherRaids;

		internal static ConfigEntry<float> OtherRaidsMaxDistance;

		internal static ConfigEntry<bool> Sound;

		internal static ConfigEntry<float> SoundVolume;

		internal static ConfigEntry<bool> SoundForOtherRaids;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Expected O, but got Unknown
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Expected O, but got Unknown
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Expected O, but got Unknown
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Language = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Language", "Auto", new ConfigDescription("Language of the banner. Auto = Ukrainian when the game is in Ukrainian, English otherwise. (The raid name itself always comes from the game's own translation.)", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Auto", "English", "Ukrainian" }), Array.Empty<object>()));
			Banner = ((BaseUnityPlugin)this).Config.Bind<bool>("Banner", "Enabled", true, "Show a small banner at the top centre of the screen while a raid is on: what it is and how long is left.");
			BannerOffsetY = ((BaseUnityPlugin)this).Config.Bind<float>("Banner", "OffsetY", 24f, new ConfigDescription("Gap between the top of the screen and the banner (in 1080p pixels; raise it if something else is drawn there).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 900f), Array.Empty<object>()));
			BannerBlinkSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Banner", "BlinkSeconds", 10f, new ConfigDescription("The banner blinks this long after a raid starts, then stays lit.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 600f), Array.Empty<object>()));
			EdgeFlash = ((BaseUnityPlugin)this).Config.Bind<bool>("EdgeFlash", "Enabled", true, "Pulse red around the screen edges when a raid starts where you are (or you walk into one).");
			EdgeFlashSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("EdgeFlash", "Seconds", 6f, new ConfigDescription("How long the red edge pulse lasts.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 60f), Array.Empty<object>()));
			OtherRaids = ((BaseUnityPlugin)this).Config.Bind<bool>("OtherRaids", "Enabled", true, "Also show raids that are not around you (at another player's base), with the player, distance and direction.");
			OtherRaidsMaxDistance = ((BaseUnityPlugin)this).Config.Bind<float>("OtherRaids", "MaxDistance", 0f, new ConfigDescription("Only show raids elsewhere closer than this many metres. 0 = any distance.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20000f), Array.Empty<object>()));
			Sound = ((BaseUnityPlugin)this).Config.Bind<bool>("Sound", "Enabled", true, "Blow a horn when a raid starts.");
			SoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Sound", "Volume", 0.7f, new ConfigDescription("Horn volume (also scaled by the game's volume settings).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			SoundForOtherRaids = ((BaseUnityPlugin)this).Config.Bind<bool>("Sound", "ForOtherRaids", true, "Also blow the horn (quieter) for raids at another player's base.");
			_harmony = new Harmony("com.budyliv.raidalert");
			_harmony.PatchAll();
			Log.LogInfo((object)"Budyliv RaidAlert 1.1.0 loaded.");
		}

		private void Update()
		{
			try
			{
				RaidAlert.Update();
			}
			catch (Exception e)
			{
				RaidAlert.Fail(e);
			}
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			RaidAlert.Destroy();
		}
	}
	[HarmonyPatch(typeof(RandEventSystem), "RPC_SetEvent")]
	internal static class SetEventPatch
	{
		private static void Postfix()
		{
			RaidAlert.LastSync = Time.time;
		}
	}
	internal static class RaidAlert
	{
		internal static float LastSync;

		private static readonly Color RaidRed = new Color(1f, 0.22f, 0.15f);

		private const float RefreshSeconds = 0.25f;

		private static string _raidKey;

		private static float _raidSeenAt;

		private static bool _flashedThisRaid;

		private static bool _wasNear;

		private static float _flashStart = -999f;

		private static float _nextRefresh;

		private static bool _failed;

		private static RectTransform _banner;

		private static Image _bannerBack;

		private static TextMeshProUGUI _bannerText;

		private static GameObject _canvas;

		private static RawImage _edge;

		private static AudioSource _audio;

		private static AudioClip _horn;

		private static readonly string[] CompassUk = new string[8] { "пн", "пн-сх", "сх", "пд-сх", "пд", "пд-зх", "зх", "пн-зх" };

		private static readonly string[] CompassEn = new string[8] { "N", "NE", "E", "SE", "S", "SW", "W", "NW" };

		private static bool Ukrainian
		{
			get
			{
				string value = Plugin.Language.Value;
				if (!(value == "Ukrainian"))
				{
					if (value == "English")
					{
						return false;
					}
					if (Localization.instance != null)
					{
						return Localization.instance.GetSelectedLanguage() == "Ukrainian";
					}
					return false;
				}
				return true;
			}
		}

		internal static void Update()
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			if (_failed)
			{
				return;
			}
			RandEventSystem instance = RandEventSystem.instance;
			Player localPlayer = Player.m_localPlayer;
			RandomEvent val = (((Object)(object)instance != (Object)null && (Object)(object)localPlayer != (Object)null) ? instance.GetCurrentRandomEvent() : null);
			if (val == null || string.IsNullOrEmpty(val.m_name))
			{
				_raidKey = null;
				_wasNear = false;
				Hide();
				AnimateEdge();
				return;
			}
			bool flag = instance.GetActiveEvent() == val;
			string text = val.m_name + "@" + Mathf.RoundToInt(val.m_pos.x) + "," + Mathf.RoundToInt(val.m_pos.z);
			float num = Utils.DistanceXZ(((Component)localPlayer).transform.position, val.m_pos);
			bool flag2 = flag || (Plugin.OtherRaids.Value && (Plugin.OtherRaidsMaxDistance.Value <= 0f || num <= Plugin.OtherRaidsMaxDistance.Value));
			if (text != _raidKey)
			{
				_raidKey = text;
				_raidSeenAt = Time.time;
				_flashedThisRaid = false;
				_wasNear = false;
				if (flag2)
				{
					Horn(flag ? 1f : 0.5f, flag);
				}
				Plugin.Log.LogInfo((object)string.Format("Raid {0} at {1:F0}, {2:F0} m away{3}.", val.m_name, val.m_pos, num, flag ? " (here)" : ""));
			}
			if (flag && !_wasNear && !_flashedThisRaid)
			{
				_flashedThisRaid = true;
				if (Plugin.EdgeFlash.Value)
				{
					_flashStart = Time.time;
				}
			}
			_wasNear = flag;
			AnimateEdge();
			if (!flag2 || !Plugin.Banner.Value)
			{
				Hide();
			}
			else
			{
				ShowBanner(val, flag, num, ((Component)localPlayer).transform.position);
			}
		}

		private static float TimeLeft(RandomEvent raid)
		{
			float num = raid.m_time;
			if ((Object)(object)ZNet.instance != (Object)null && !ZNet.instance.IsServer())
			{
				num += Mathf.Clamp(Time.time - LastSync, 0f, 2.5f);
			}
			return Mathf.Max(0f, raid.m_duration - num);
		}

		private static string Title(RandomEvent raid)
		{
			return ((!string.IsNullOrEmpty(raid.m_startMessage) && Localization.instance != null) ? Localization.instance.Localize(raid.m_startMessage) : raid.m_name).Trim().TrimEnd('.', '…', '!');
		}

		private static string Owner(RandomEvent raid)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)ZNet.instance == (Object)null)
			{
				return null;
			}
			string result = null;
			float num = raid.m_eventRange;
			foreach (PlayerInfo player in ZNet.instance.GetPlayerList())
			{
				if (player.m_publicPosition)
				{
					float num2 = Utils.DistanceXZ(player.m_position, raid.m_pos);
					if (num2 < num)
					{
						num = num2;
						result = player.m_name;
					}
				}
			}
			return result;
		}

		private static string Direction(Vector3 from, Vector3 to)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.RoundToInt(Mathf.Repeat(Mathf.Atan2(to.x - from.x, to.z - from.z) * 57.29578f, 360f) / 45f) % 8;
			return (Ukrainian ? CompassUk : CompassEn)[num];
		}

		private static string Distance(float metres)
		{
			bool ukrainian = Ukrainian;
			if (metres < 1000f)
			{
				return string.Format("{0} {1}", Mathf.RoundToInt(metres / 10f) * 10, ukrainian ? "м" : "m");
			}
			string text = (metres / 1000f).ToString("0.0", CultureInfo.InvariantCulture);
			if (!ukrainian)
			{
				return text + " km";
			}
			return text.Replace('.', ',') + " км";
		}

		private static void ShowBanner(RandomEvent raid, bool near, float distance, Vector3 playerPos)
		{
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < _nextRefresh && (Object)(object)_banner != (Object)null && ((Component)_banner).gameObject.activeSelf)
			{
				Blink(near);
				return;
			}
			_nextRefresh = Time.time + 0.25f;
			if (EnsureBanner())
			{
				int num = Mathf.CeilToInt(TimeLeft(raid));
				string text = $"{num / 60}:{num % 60:00}";
				string text2;
				if (near)
				{
					text2 = "<b>" + (Ukrainian ? "РЕЙД!" : "RAID!") + "</b>  " + Title(raid) + "  <b>" + text + "</b>";
				}
				else
				{
					string text3 = Owner(raid);
					bool ukrainian = Ukrainian;
					string text4 = ((!ukrainian) ? ((text3 != null) ? ("Raid at " + text3) : "Raid elsewhere") : ((text3 != null) ? ("Рейд біля " + text3) : "Рейд деінде"));
					string text5 = (ukrainian ? (Distance(distance) + " на " + Direction(playerPos, raid.m_pos)) : (Distance(distance) + " " + Direction(playerPos, raid.m_pos)));
					text2 = "<b>" + text4 + "</b>: " + Title(raid) + "  ·  " + text5 + "  ·  <b>" + text + "</b>";
				}
				((TMP_Text)_bannerText).text = text2;
				((TMP_Text)_bannerText).fontSize = (near ? 21f : 17f);
				Place();
				((Component)_banner).gameObject.SetActive(true);
				Blink(near);
			}
		}

		private static void Blink(bool near)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			float num = Time.time - _raidSeenAt;
			float num2 = 1f;
			if (near && num < Plugin.BannerBlinkSeconds.Value)
			{
				num2 = 0.45f + 0.55f * (0.5f + 0.5f * Mathf.Cos(num * MathF.PI * 2f * 1.25f));
			}
			((Graphic)_bannerText).color = new Color(1f, near ? 0.85f : 0.9f, near ? 0.8f : 0.85f, num2);
			Color color = (near ? new Color(0.45f, 0.03f, 0.02f, 0.75f) : new Color(0.1f, 0.05f, 0.04f, 0.65f));
			color.a *= Mathf.Lerp(0.6f, 1f, num2);
			((Graphic)_bannerBack).color = color;
		}

		private static void Place()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			_banner.anchoredPosition = new Vector2(0f, 0f - Plugin.BannerOffsetY.Value);
			Vector2 preferredValues = ((TMP_Text)_bannerText).GetPreferredValues(((TMP_Text)_bannerText).text, 640f, 0f);
			_banner.sizeDelta = new Vector2(Mathf.Min(preferredValues.x, 640f) + 28f, preferredValues.y + 10f);
		}

		private static bool EnsureBanner()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_banner != (Object)null)
			{
				return true;
			}
			TMP_Text val = (((Object)(object)MessageHud.instance != (Object)null) ? MessageHud.instance.m_messageText : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			EnsureCanvas();
			GameObject val2 = new GameObject("BudylivRaidAlert_Banner", new Type[1] { typeof(RectTransform) });
			_banner = (RectTransform)val2.transform;
			((Transform)_banner).SetParent(_canvas.transform, false);
			RectTransform banner = _banner;
			RectTransform banner2 = _banner;
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(0.5f, 1f);
			banner2.anchorMax = val3;
			banner.anchorMin = val3;
			_banner.pivot = new Vector2(0.5f, 1f);
			_banner.sizeDelta = new Vector2(300f, 40f);
			_bannerBack = val2.AddComponent<Image>();
			((Graphic)_bannerBack).raycastTarget = false;
			GameObject val4 = new GameObject("text", new Type[1] { typeof(RectTransform) });
			RectTransform val5 = (RectTransform)val4.transform;
			((Transform)val5).SetParent((Transform)(object)_banner, false);
			val5.anchorMin = Vector2.zero;
			val5.anchorMax = Vector2.one;
			val5.offsetMin = new Vector2(8f, 3f);
			val5.offsetMax = new Vector2(-8f, -3f);
			_bannerText = val4.AddComponent<TextMeshProUGUI>();
			((TMP_Text)_bannerText).font = val.font;
			((TMP_Text)_bannerText).fontSharedMaterial = val.fontSharedMaterial;
			((TMP_Text)_bannerText).alignment = (TextAlignmentOptions)514;
			((TMP_Text)_bannerText).enableWordWrapping = false;
			((TMP_Text)_bannerText).richText = true;
			((Graphic)_bannerText).raycastTarget = false;
			val2.SetActive(false);
			return true;
		}

		private static void Hide()
		{
			if ((Object)(object)_banner != (Object)null && ((Component)_banner).gameObject.activeSelf)
			{
				((Component)_banner).gameObject.SetActive(false);
			}
		}

		private static void AnimateEdge()
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			float num = Time.time - _flashStart;
			float value = Plugin.EdgeFlashSeconds.Value;
			if (!(num >= 0f) || !(num < value) || !Plugin.EdgeFlash.Value)
			{
				if ((Object)(object)_edge != (Object)null && ((Behaviour)_edge).enabled)
				{
					((Behaviour)_edge).enabled = false;
				}
			}
			else if (EnsureEdge())
			{
				float num2 = 1f - Mathf.SmoothStep(0f, 1f, num / value);
				float num3 = 0.35f + 0.65f * (0.5f + 0.5f * Mathf.Cos(num * MathF.PI * 2f * 0.9f));
				Color raidRed = RaidRed;
				raidRed.a = 0.85f * num2 * num3;
				((Graphic)_edge).color = raidRed;
				((Behaviour)_edge).enabled = true;
			}
		}

		private static bool EnsureEdge()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_edge != (Object)null)
			{
				return true;
			}
			EnsureCanvas();
			GameObject val = new GameObject("edge", new Type[1] { typeof(RectTransform) });
			RectTransform val2 = (RectTransform)val.transform;
			((Transform)val2).SetParent(_canvas.transform, false);
			((Transform)val2).SetAsFirstSibling();
			val2.anchorMin = Vector2.zero;
			val2.anchorMax = Vector2.one;
			Vector2 offsetMin = (val2.offsetMax = Vector2.zero);
			val2.offsetMin = offsetMin;
			_edge = val.AddComponent<RawImage>();
			((Graphic)_edge).raycastTarget = false;
			_edge.texture = (Texture)(object)MakeEdgeTexture();
			((Behaviour)_edge).enabled = false;
			return true;
		}

		private static void EnsureCanvas()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_canvas != (Object)null))
			{
				_canvas = new GameObject("BudylivRaidAlert_UI");
				Object.DontDestroyOnLoad((Object)(object)_canvas);
				Canvas obj = _canvas.AddComponent<Canvas>();
				obj.renderMode = (RenderMode)0;
				obj.sortingOrder = 5;
				CanvasScaler obj2 = _canvas.AddComponent<CanvasScaler>();
				obj2.uiScaleMode = (ScaleMode)1;
				obj2.referenceResolution = new Vector2(1920f, 1080f);
				obj2.matchWidthOrHeight = 0.5f;
			}
		}

		private static Texture2D MakeEdgeTexture()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(128, 128, (TextureFormat)4, false)
			{
				wrapMode = (TextureWrapMode)1,
				filterMode = (FilterMode)1,
				name = "BudylivRaidAlert_Edge",
				hideFlags = (HideFlags)32
			};
			Color32[] array = (Color32[])(object)new Color32[16384];
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = ((float)j + 0.5f) / 128f;
					float num2 = ((float)i + 0.5f) / 128f;
					float num3 = Mathf.Min(Mathf.Min(num, 1f - num), Mathf.Min(num2, 1f - num2));
					float num4 = 1f - Mathf.Clamp01(num3 / 0.16f);
					num4 *= num4;
					array[i * 128 + j] = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)Mathf.RoundToInt(num4 * 255f));
				}
			}
			val.SetPixels32(array);
			val.Apply(false, true);
			return val;
		}

		private static void Horn(float loudness, bool near)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			if (!Plugin.Sound.Value || (!near && !Plugin.SoundForOtherRaids.Value))
			{
				return;
			}
			if ((Object)(object)_audio == (Object)null)
			{
				GameObject val = new GameObject("BudylivRaidAlert_Audio");
				Object.DontDestroyOnLoad((Object)val);
				_audio = val.AddComponent<AudioSource>();
				_audio.spatialBlend = 0f;
				_audio.playOnAwake = false;
				if ((Object)(object)AudioMan.instance != (Object)null && (Object)(object)AudioMan.instance.m_guiMixer != (Object)null)
				{
					_audio.outputAudioMixerGroup = AudioMan.instance.m_guiMixer;
				}
			}
			if ((Object)(object)_horn == (Object)null)
			{
				_horn = MakeHorn();
			}
			_audio.PlayOneShot(_horn, Plugin.SoundVolume.Value * loudness);
		}

		private static AudioClip MakeHorn()
		{
			(float, float, float)[] obj = new(float, float, float)[2]
			{
				(0f, 0.9f, 110f),
				(1.05f, 1.7f, 146.8f)
			};
			float[] array = new float[125684];
			(float, float, float)[] array2 = obj;
			for (int i = 0; i < array2.Length; i++)
			{
				(float, float, float) tuple = array2[i];
				int num = (int)(tuple.Item1 * 44100f);
				int num2 = (int)(tuple.Item2 * 44100f);
				double num3 = 0.0;
				for (int j = 0; j < num2 && num + j < array.Length; j++)
				{
					float num4 = (float)j / 44100f;
					float num5 = Mathf.Lerp(0.93f, 1f, Mathf.Clamp01(num4 / 0.18f));
					float num6 = 1f + 0.006f * Mathf.Sin(32.67256f * num4) * Mathf.Clamp01((num4 - 0.3f) * 2f);
					num3 += Math.PI * 2.0 * (double)tuple.Item3 * (double)num5 * (double)num6 / 44100.0;
					float num7 = Mathf.Clamp01(num4 / 0.12f);
					float num8 = Mathf.Clamp01((tuple.Item2 - num4) / 0.35f);
					float num9 = num7 * num8;
					float num10 = 0.55f + 0.45f * num7;
					float num11 = 0f;
					for (int k = 1; k <= 9; k++)
					{
						num11 += Mathf.Pow(num10, (float)(k - 1)) * (float)Math.Sin(num3 * (double)k) / (float)k;
					}
					array[num + j] += num11 * num9;
				}
			}
			float num12 = 0f;
			float[] array3 = array;
			foreach (float num13 in array3)
			{
				num12 = Mathf.Max(num12, Mathf.Abs(num13));
			}
			if (num12 > 0f)
			{
				for (int l = 0; l < array.Length; l++)
				{
					array[l] = array[l] / num12 * 0.8f;
				}
			}
			AudioClip obj2 = AudioClip.Create("BudylivRaidAlert_Horn", array.Length, 1, 44100, false);
			obj2.SetData(array, 0);
			((Object)obj2).hideFlags = (HideFlags)32;
			return obj2;
		}

		internal static void Fail(Exception e)
		{
			_failed = true;
			Plugin.Log.LogError((object)$"Raid alert stopped after an error: {e}");
			Hide();
		}

		internal static void Destroy()
		{
			if ((Object)(object)_canvas != (Object)null)
			{
				Object.Destroy((Object)(object)_canvas);
			}
			if ((Object)(object)_audio != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_audio).gameObject);
			}
		}
	}
}