Decompiled source of BigWalkRadioMusic v2.2.1

plugins/BigWalkRadioMusic.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Microsoft.Win32;
using Mirror;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("BigWalkRadioMusic")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BigWalkRadioMusic")]
[assembly: AssemblyTitle("BigWalkRadioMusic")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 BigWalkRadioMusic
{
	internal static class AtmosRig
	{
		internal sealed class Speaker
		{
			internal string Id;

			internal AudioSource Src;

			internal AudioLowPassFilter Lpf;

			internal AudioHighPassFilter Hpf;

			internal AudioReverbFilter Rev;

			internal float Az;

			internal float El;

			internal float Dist;

			internal float Gain;

			internal float Delay;

			internal float LpHz;

			internal float HpHz;

			internal float Blend;

			internal float Pan;

			internal bool Reverb;

			internal bool Height;

			internal bool Lfe;

			internal bool Ambient;
		}

		internal const int Count = 12;

		private const int ObjCount = 2;

		private static readonly Speaker[] _sp = new Speaker[12];

		private static readonly AudioSource[] _obj = (AudioSource[])(object)new AudioSource[2];

		private static bool _ready;

		private static bool _objectsReady;

		private static float _norm = 0.5f;

		private static Vector3 _center;

		private static float _yaw;

		private static float _radius = 6f;

		private static bool _geometrySet;

		private static string _spatializer = "无(Unity 内置 3D panning,无 HRTF)";

		private static bool _hasSpatializer;

		private static AudioClip _clip;

		private static float _clipStart;

		private static float _lastGain = -999f;

		private static float _lastMix = -999f;

		private static float _lastHg = -999f;

		private static float _lastLg = -999f;

		private static float _lastRadius = -999f;

		private static float _lastYaw = 1E+09f;

		private static bool _lastForce2d;

		private static bool _applied;

		private static bool _objectsMuted = true;

		private static bool _paused;

		private static Vector3 _lastCenter = new Vector3(1E+09f, 1E+09f, 1E+09f);

		private static float[] _spec;

		private static float _beat;

		private static float _env;

		private static float _bassMax = 1E-09f;

		private static bool _beatLogged;

		private static float _beatAt;

		internal static bool Ready => _ready;

		internal static string Spatializer => _spatializer;

		internal static int ChannelCount => 12;

		internal static bool HasGeometry => _geometrySet;

		internal static Vector3 Center => _center;

		internal static float Yaw => _yaw;

		internal static bool HasClipNow => (Object)_clip != (Object)null;

		internal static bool PausedNow => _paused;

		internal static float Duration
		{
			get
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Expected O, but got Unknown
				if (!((Object)_clip != (Object)null))
				{
					return 0f;
				}
				return _clip.length;
			}
		}

		internal static float Position
		{
			get
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_0034: Expected O, but got Unknown
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0067: Expected O, but got Unknown
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_007f: Expected O, but got Unknown
				Speaker speaker = _sp[2];
				if (speaker != null && (Object)speaker.Src != (Object)null && (Object)speaker.Src.clip != (Object)null)
				{
					try
					{
						return speaker.Src.time;
					}
					catch
					{
					}
				}
				for (int i = 0; i < 12; i++)
				{
					Speaker speaker2 = _sp[i];
					if (speaker2 != null && !((Object)speaker2.Src == (Object)null) && !((Object)speaker2.Src.clip == (Object)null))
					{
						try
						{
							return speaker2.Src.time;
						}
						catch
						{
						}
					}
				}
				return 0f;
			}
		}

		internal static bool Playing
		{
			get
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				Speaker speaker = _sp[2];
				if (speaker != null && (Object)speaker.Src != (Object)null)
				{
					try
					{
						return speaker.Src.isPlaying;
					}
					catch
					{
					}
				}
				return false;
			}
		}

		internal static bool Finished
		{
			get
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Expected O, but got Unknown
				if ((Object)_clip == (Object)null)
				{
					return false;
				}
				if (Playing)
				{
					return false;
				}
				float length = _clip.length;
				if (length < 1f)
				{
					return false;
				}
				return Position >= length - 1.2f;
			}
		}

		internal static float Beat => _beat;

		private static Speaker Sp(string id, float az, float el, float dist, float gain, float delay, float lp, float hp, bool reverb, float blend, float pan, bool height = false, bool lfe = false)
		{
			return new Speaker
			{
				Id = id,
				Az = az,
				El = el,
				Dist = dist,
				Gain = gain,
				Delay = delay,
				LpHz = lp,
				HpHz = hp,
				Reverb = reverb,
				Blend = blend,
				Pan = pan,
				Height = height,
				Lfe = lfe,
				Ambient = (blend > 0.5f && (lp > 0f || hp > 0f))
			};
		}

		private static Speaker[] Table()
		{
			return new Speaker[12]
			{
				Sp("ScreenL", 0f, 0f, 1f, 0.5f, 0f, 0f, 0f, reverb: false, 0f, -0.9f),
				Sp("ScreenR", 0f, 0f, 1f, 0.5f, 0f, 0f, 0f, reverb: false, 0f, 0.9f),
				Sp("Center", 0f, 0f, 1f, 0.7f, 0f, 0f, 0f, reverb: false, 1f, 0f),
				Sp("SurrL", -90f, 0f, 1f, 0.62f, 0.013f, 8000f, 120f, reverb: false, 1f, 0f),
				Sp("SurrR", 90f, 0f, 1f, 0.62f, 0.013f, 8000f, 120f, reverb: false, 1f, 0f),
				Sp("RearL", -145f, 0f, 1f, 0.55f, 0.021f, 6000f, 150f, reverb: true, 1f, 0f),
				Sp("RearR", 145f, 0f, 1f, 0.55f, 0.021f, 6000f, 150f, reverb: true, 1f, 0f),
				Sp("TopFL", -45f, 48f, 0.8f, 0.48f, 0.019f, 10000f, 500f, reverb: true, 1f, 0f, height: true),
				Sp("TopFR", 45f, 48f, 0.8f, 0.48f, 0.019f, 10000f, 500f, reverb: true, 1f, 0f, height: true),
				Sp("TopRL", -135f, 48f, 0.8f, 0.44f, 0.025f, 10000f, 500f, reverb: true, 1f, 0f, height: true),
				Sp("TopRR", 135f, 48f, 0.8f, 0.44f, 0.025f, 10000f, 500f, reverb: true, 1f, 0f, height: true),
				Sp("LFE", 0f, -10f, 0.35f, 0.75f, 0f, 120f, 25f, reverb: false, 0.6f, 0f, height: false, lfe: true)
			};
		}

		internal static void Ensure()
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			if (_ready)
			{
				return;
			}
			try
			{
				string spatializerPluginName = AudioSettings.GetSpatializerPluginName();
				_hasSpatializer = !string.IsNullOrEmpty(spatializerPluginName);
				if (_hasSpatializer)
				{
					_spatializer = spatializerPluginName;
				}
			}
			catch
			{
			}
			Speaker[] array = Table();
			float num = 0f;
			for (int i = 0; i < 12; i++)
			{
				num += array[i].Gain * array[i].Gain;
			}
			_norm = 1f / Mathf.Max(0.01f, Mathf.Sqrt(num));
			for (int j = 0; j < 12; j++)
			{
				try
				{
					GameObject val = new GameObject("BigWalkAtmos_" + array[j].Id);
					Object.DontDestroyOnLoad((Object)val);
					AudioSource val2 = val.AddComponent<AudioSource>();
					val2.playOnAwake = false;
					val2.loop = false;
					val2.volume = 0f;
					val2.spatialBlend = array[j].Blend;
					val2.panStereo = array[j].Pan;
					val2.rolloffMode = (AudioRolloffMode)1;
					val2.minDistance = 6f;
					val2.maxDistance = 41f;
					val2.spread = 0f;
					val2.dopplerLevel = 0f;
					val2.bypassEffects = false;
					val2.bypassListenerEffects = false;
					val2.bypassReverbZones = true;
					if (_hasSpatializer)
					{
						try
						{
							val2.spatialize = true;
						}
						catch
						{
						}
					}
					array[j].Src = val2;
					if (array[j].LpHz > 0f)
					{
						try
						{
							AudioLowPassFilter val3 = val.AddComponent<AudioLowPassFilter>();
							val3.cutoffFrequency = array[j].LpHz;
							val3.lowpassResonanceQ = 0.8f;
							array[j].Lpf = val3;
						}
						catch
						{
						}
					}
					if (array[j].HpHz > 0f)
					{
						try
						{
							AudioHighPassFilter val4 = val.AddComponent<AudioHighPassFilter>();
							val4.cutoffFrequency = array[j].HpHz;
							val4.highpassResonanceQ = 0.8f;
							array[j].Hpf = val4;
						}
						catch
						{
						}
					}
					if (array[j].Reverb)
					{
						try
						{
							AudioReverbFilter val5 = val.AddComponent<AudioReverbFilter>();
							val5.reverbPreset = (AudioReverbPreset)27;
							val5.dryLevel = 0f;
							val5.room = -14f;
							val5.roomHF = -10f;
							val5.decayTime = 1.05f;
							val5.decayHFRatio = 0.55f;
							val5.reflectionsLevel = -20f;
							val5.reflectionsDelay = 0.015f;
							val5.reverbLevel = -9f;
							val5.reverbDelay = 0.018f;
							val5.diffusion = 88f;
							val5.density = 70f;
							val5.hfReference = 5000f;
							array[j].Rev = val5;
						}
						catch
						{
						}
					}
					_sp[j] = array[j];
				}
				catch (Exception ex)
				{
					Plugin.Warn("创建声道失败 idx=" + j + ":" + ex.GetBaseException().Message);
				}
			}
			_ready = true;
			Plugin.Info("全景声渲染器就绪:7.1.4 / " + 12 + " 声道 | 空间化插件:" + _spatializer + " | 头顶线索由「带通 + 短混响 + 哈斯延迟」合成");
		}

		private static void EnsureObjects()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			if (_objectsReady)
			{
				return;
			}
			for (int i = 0; i < 2; i++)
			{
				try
				{
					GameObject val = new GameObject("BigWalkAtmos_Object" + i);
					Object.DontDestroyOnLoad((Object)val);
					AudioSource val2 = val.AddComponent<AudioSource>();
					val2.playOnAwake = false;
					val2.loop = false;
					val2.volume = 0f;
					val2.spatialBlend = 1f;
					val2.rolloffMode = (AudioRolloffMode)1;
					val2.minDistance = 2f;
					val2.maxDistance = 60f;
					val2.spread = 0f;
					val2.dopplerLevel = 0f;
					val2.bypassEffects = false;
					val2.bypassListenerEffects = false;
					val2.bypassReverbZones = true;
					try
					{
						val.AddComponent<AudioLowPassFilter>().cutoffFrequency = 6500f;
					}
					catch
					{
					}
					try
					{
						val.AddComponent<AudioHighPassFilter>().cutoffFrequency = 800f;
					}
					catch
					{
					}
					_obj[i] = val2;
				}
				catch (Exception ex)
				{
					Plugin.Warn("创建动态对象失败:" + ex.GetBaseException().Message);
				}
			}
			_objectsReady = true;
			Plugin.Info("已创建 " + 2 + " 个动态全景对象");
		}

		internal static void SetGeometry(Vector3 center, float yaw, float radius)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			_center = center;
			_yaw = yaw;
			_radius = Mathf.Clamp(radius, 1f, 15f);
			_geometrySet = true;
		}

		internal static void Refresh(float t)
		{
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Expected O, but got Unknown
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Expected O, but got Unknown
			if (!_ready || !_geometrySet || _paused)
			{
				return;
			}
			float num = ((Plugin.Gain != null) ? Plugin.Gain.Value : 1f);
			float num2 = ((Plugin.AtmosMix != null) ? Mathf.Clamp01(Plugin.AtmosMix.Value) : 1f);
			float num3 = ((Plugin.HeightGain != null) ? Mathf.Clamp(Plugin.HeightGain.Value, 0f, 2f) : 1f);
			float num4 = ((Plugin.LfeGain != null) ? Mathf.Clamp(Plugin.LfeGain.Value, 0f, 2f) : 1f);
			bool flag = Plugin.Force2D != null && Plugin.Force2D.Value;
			bool flag2 = Plugin.MovingObjects != null && Plugin.MovingObjects.Value;
			float baseV = Mathf.Clamp01(0.2f * num) * _norm;
			float radius = _radius;
			int num5;
			int num6;
			if (_applied && !(Mathf.Abs(num - _lastGain) > 0.001f) && !(Mathf.Abs(num2 - _lastMix) > 0.001f) && !(Mathf.Abs(num3 - _lastHg) > 0.001f) && !(Mathf.Abs(num4 - _lastLg) > 0.001f) && !(Mathf.Abs(radius - _lastRadius) > 0.01f))
			{
				num5 = ((flag != _lastForce2d) ? 1 : 0);
				if (num5 == 0 && !(Mathf.Abs(_yaw - _lastYaw) > 0.05f))
				{
					Vector3 val = _center - _lastCenter;
					num6 = ((((Vector3)(ref val)).sqrMagnitude > 0.0004f) ? 1 : 0);
					goto IL_019a;
				}
			}
			else
			{
				num5 = 1;
			}
			num6 = 1;
			goto IL_019a;
			IL_019a:
			bool flag3 = (byte)num6 != 0;
			if (num5 != 0)
			{
				_lastGain = num;
				_lastMix = num2;
				_lastHg = num3;
				_lastLg = num4;
				_lastRadius = radius;
				_lastForce2d = flag;
				_applied = true;
				for (int i = 0; i < 12; i++)
				{
					Speaker speaker = _sp[i];
					if (speaker != null && !((Object)speaker.Src == (Object)null))
					{
						Place(speaker, i, num2, radius);
						Acoustics(speaker, num2, radius, baseV, num3, num4, flag);
					}
				}
			}
			else if (flag3)
			{
				for (int j = 0; j < 12; j++)
				{
					Speaker speaker2 = _sp[j];
					if (speaker2 != null && !((Object)speaker2.Src == (Object)null))
					{
						Place(speaker2, j, num2, radius);
					}
				}
			}
			if (flag3)
			{
				_lastYaw = _yaw;
				_lastCenter = _center;
			}
			RefreshObjects(t, flag2, baseV);
		}

		private static void Place(Speaker s, int i, float mix, float r)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Lerp((float)i * 51.42857f, s.Az, mix);
			float num2 = s.El * mix;
			float num3 = Mathf.Lerp(1f, s.Dist, mix);
			float num4 = (_yaw + num) * ((float)Math.PI / 180f);
			float num5 = num2 * ((float)Math.PI / 180f);
			float num6 = r * num3;
			float num7 = Mathf.Cos(num5) * num6;
			try
			{
				((Component)s.Src).transform.position = _center + new Vector3(Mathf.Sin(num4) * num7, Mathf.Sin(num5) * num6, Mathf.Cos(num4) * num7);
			}
			catch
			{
			}
		}

		private static void Acoustics(Speaker s, float mix, float r, float baseV, float hg, float lg, bool force2d)
		{
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Expected O, but got Unknown
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			float spatialBlend = (force2d ? 0f : Mathf.Lerp(1f, s.Blend, mix));
			try
			{
				s.Src.spatialBlend = spatialBlend;
				s.Src.panStereo = s.Pan * mix;
				s.Src.minDistance = Mathf.Max(0.5f, r);
				s.Src.maxDistance = r + 35f;
				s.Src.rolloffMode = (AudioRolloffMode)1;
			}
			catch
			{
			}
			float num = (s.Height ? (s.Gain * hg * mix) : ((!s.Lfe) ? Mathf.Lerp(0.8f, s.Gain, mix) : (s.Gain * lg * mix)));
			try
			{
				s.Src.volume = Mathf.Clamp01(baseV * num);
			}
			catch
			{
			}
			if ((Object)s.Lpf != (Object)null)
			{
				try
				{
					((Behaviour)s.Lpf).enabled = mix > 0.02f;
					s.Lpf.cutoffFrequency = Mathf.Lerp(22000f, s.LpHz, mix);
				}
				catch
				{
				}
			}
			if ((Object)s.Hpf != (Object)null)
			{
				try
				{
					((Behaviour)s.Hpf).enabled = mix > 0.02f;
					s.Hpf.cutoffFrequency = Mathf.Lerp(10f, s.HpHz, mix);
				}
				catch
				{
				}
			}
			if ((Object)s.Rev != (Object)null)
			{
				try
				{
					((Behaviour)s.Rev).enabled = mix > 0.02f;
					s.Rev.reverbLevel = Mathf.Lerp(-60f, -9f, mix);
				}
				catch
				{
				}
			}
		}

		private static void RefreshObjects(float t, bool on, float baseV)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Expected O, but got Unknown
			//IL_0102: 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_0138: Unknown result type (might be due to invalid IL or missing references)
			if (!on)
			{
				if (_objectsMuted)
				{
					return;
				}
				for (int i = 0; i < 2; i++)
				{
					if ((Object)_obj[i] != (Object)null)
					{
						try
						{
							_obj[i].volume = 0f;
						}
						catch
						{
						}
					}
				}
				_objectsMuted = true;
				return;
			}
			_objectsMuted = false;
			EnsureObjects();
			for (int j = 0; j < 2; j++)
			{
				AudioSource val = _obj[j];
				if ((Object)val == (Object)null)
				{
					continue;
				}
				try
				{
					if ((Object)val.clip == (Object)null && (Object)_clip != (Object)null)
					{
						val.clip = _clip;
						if (_clipStart > 0.05f)
						{
							val.time = _clipStart;
						}
						val.Play();
					}
					float num = (t * 32f + (float)j * 180f) * ((float)Math.PI / 180f);
					float num2 = ((j == 0) ? 30f : (-6f)) * ((float)Math.PI / 180f);
					float num3 = _radius * 1.05f;
					((Component)val).transform.position = _center + new Vector3(Mathf.Sin(num) * Mathf.Cos(num2) * num3, Mathf.Sin(num2) * num3, Mathf.Cos(num) * Mathf.Cos(num2) * num3);
					float num4 = 0.35f + 0.65f * (0.5f + 0.5f * Mathf.Sin(t * 1.7f + (float)j * 2.4f));
					val.volume = Mathf.Clamp01(baseV * 0.55f * num4);
				}
				catch
				{
				}
			}
		}

		internal static void SetClip(AudioClip clip, float startSec)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			if ((Object)clip == (Object)null)
			{
				return;
			}
			Ensure();
			_clip = clip;
			_clipStart = Mathf.Max(0f, startSec);
			_paused = false;
			_objectsMuted = false;
			_applied = false;
			float num = Mathf.Clamp(_clipStart, 0f, Mathf.Max(0f, clip.length - 0.05f));
			for (int i = 0; i < 12; i++)
			{
				Speaker speaker = _sp[i];
				if (speaker == null || (Object)speaker.Src == (Object)null)
				{
					continue;
				}
				try
				{
					speaker.Src.clip = clip;
					if (num > 0.05f)
					{
						speaker.Src.time = num;
					}
					speaker.Src.Play();
				}
				catch
				{
				}
			}
			for (int j = 0; j < 2; j++)
			{
				if ((Object)_obj[j] == (Object)null)
				{
					continue;
				}
				try
				{
					_obj[j].clip = clip;
					if (num > 0.05f)
					{
						_obj[j].time = num;
					}
					_obj[j].Play();
				}
				catch
				{
				}
			}
			if (_geometrySet)
			{
				Refresh(Time.unscaledTime);
			}
		}

		internal static void SeekTo(float sec)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			if ((Object)_clip == (Object)null)
			{
				return;
			}
			float time = (_clipStart = Mathf.Clamp(sec, 0f, Mathf.Max(0f, _clip.length - 0.35f)));
			for (int i = 0; i < 12; i++)
			{
				Speaker speaker = _sp[i];
				if (speaker != null && !((Object)speaker.Src == (Object)null) && !((Object)speaker.Src.clip == (Object)null))
				{
					try
					{
						speaker.Src.time = time;
					}
					catch
					{
					}
				}
			}
			for (int j = 0; j < 2; j++)
			{
				if (!((Object)_obj[j] == (Object)null) && !((Object)_obj[j].clip == (Object)null))
				{
					try
					{
						_obj[j].time = time;
					}
					catch
					{
					}
				}
			}
		}

		internal static void PlayAll()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			_paused = false;
			_applied = false;
			_objectsMuted = false;
			for (int i = 0; i < 12; i++)
			{
				if (_sp[i] != null && (Object)_sp[i].Src != (Object)null)
				{
					try
					{
						_sp[i].Src.Play();
					}
					catch
					{
					}
				}
			}
			for (int j = 0; j < 2; j++)
			{
				if (!((Object)_obj[j] == (Object)null) && !((Object)_obj[j].clip == (Object)null))
				{
					try
					{
						_obj[j].Play();
					}
					catch
					{
					}
				}
			}
			if (_geometrySet)
			{
				Refresh(Time.unscaledTime);
			}
		}

		internal static void PauseAll()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			_paused = true;
			for (int i = 0; i < 12; i++)
			{
				if (_sp[i] != null && (Object)_sp[i].Src != (Object)null)
				{
					try
					{
						_sp[i].Src.Pause();
					}
					catch
					{
					}
				}
			}
			for (int j = 0; j < 2; j++)
			{
				if (!((Object)_obj[j] == (Object)null))
				{
					try
					{
						_obj[j].volume = 0f;
						_obj[j].Pause();
					}
					catch
					{
					}
				}
			}
			_objectsMuted = true;
		}

		internal static void StopAll()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			_clip = null;
			_paused = true;
			_objectsMuted = true;
			_applied = false;
			for (int i = 0; i < 12; i++)
			{
				if (_sp[i] != null && !((Object)_sp[i].Src == (Object)null))
				{
					try
					{
						_sp[i].Src.Stop();
						_sp[i].Src.clip = null;
					}
					catch
					{
					}
				}
			}
			for (int j = 0; j < 2; j++)
			{
				if (!((Object)_obj[j] == (Object)null))
				{
					try
					{
						_obj[j].Stop();
						_obj[j].clip = null;
						_obj[j].volume = 0f;
					}
					catch
					{
					}
				}
			}
		}

		internal static void UpdateBeat()
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			if (Plugin.ShowLyric == null || !Plugin.ShowLyric.Value || Plugin.LyricBeat == null || Plugin.LyricBeat.Value <= 0.01f)
			{
				_beat = 0f;
				return;
			}
			Speaker speaker = ((_sp[2] != null) ? _sp[2] : _sp[0]);
			if (speaker == null || (Object)speaker.Src == (Object)null)
			{
				_beat = 0f;
				return;
			}
			bool flag = false;
			try
			{
				flag = speaker.Src.isPlaying && (Object)speaker.Src.clip != (Object)null;
			}
			catch
			{
			}
			if (!flag)
			{
				_beat = 0f;
				_env = 0f;
				return;
			}
			if (_spec == null)
			{
				_spec = new float[512];
			}
			try
			{
				speaker.Src.GetSpectrumData(Il2CppStructArray<float>.op_Implicit(_spec), 0, (FFTWindow)5);
			}
			catch
			{
				_beat = 0f;
				return;
			}
			float num = 0f;
			for (int i = 1; i <= 5; i++)
			{
				num += _spec[i];
			}
			num *= 0.2f;
			_bassMax = Mathf.Max(num, _bassMax * 0.998f);
			if (_bassMax < 1E-09f)
			{
				_beat = 0f;
				return;
			}
			float num2 = Mathf.Sqrt(Mathf.Clamp01(num / _bassMax));
			if (!_beatLogged)
			{
				if (_beatAt <= 0f)
				{
					_beatAt = Time.unscaledTime + 2f;
				}
				else if (Time.unscaledTime >= _beatAt)
				{
					_beatLogged = true;
					Plugin.Info("歌词跳动诊断:低频能量 " + num.ToString("0.0000000") + "(峰值 " + _bassMax.ToString("0.0000000") + ")→ 强度 " + num2.ToString("0.000") + ((num <= 0f) ? "(为 0,说明 FFT 拿不到数据)" : "(正常)"));
				}
			}
			if (num2 < 0.012f)
			{
				_env = Mathf.Lerp(_env, num2, 0.05f);
				_beat = Mathf.Lerp(_beat, 0f, 0.25f);
				return;
			}
			float num3 = Mathf.Max(0.015f, _env);
			float num4 = Mathf.Clamp01((num2 - _env) / (num3 * 0.85f));
			_env = Mathf.Lerp(_env, num2, 0.05f);
			_beat = ((num4 > _beat) ? Mathf.Lerp(_beat, num4, 0.75f) : Mathf.Lerp(_beat, num4, 0.1f));
		}

		internal static void SelfTestBeat()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			GameObject val = null;
			try
			{
				val = new GameObject("BigWalkBeatProbe");
				Object.DontDestroyOnLoad((Object)val);
				AudioSource obj = val.AddComponent<AudioSource>();
				obj.playOnAwake = false;
				obj.volume = 0f;
				AudioClip clip = AudioClip.Create("beatprobe", 4410, 1, 44100, false);
				obj.clip = clip;
				obj.Play();
				float[] array = new float[512];
				obj.GetSpectrumData(Il2CppStructArray<float>.op_Implicit(array), 0, (FFTWindow)5);
				float num = 0f;
				for (int i = 0; i < array.Length; i++)
				{
					num += array[i];
				}
				Plugin.Info("歌词跳动自检通过:频谱接口可用(512 点 FFT,静音样本和=" + num.ToString("0.0000") + ")");
			}
			catch (Exception ex)
			{
				Plugin.Warn("歌词跳动自检失败(跳动会一直不动):" + ex.GetBaseException().Message);
			}
			finally
			{
				try
				{
					if ((Object)val != (Object)null)
					{
						Object.Destroy((Object)val);
					}
				}
				catch
				{
				}
			}
		}
	}
	internal static class AudioMeta
	{
		private static readonly int[] BrMpeg1L3 = new int[15]
		{
			0, 32, 40, 48, 56, 64, 80, 96, 112, 128,
			160, 192, 224, 256, 320
		};

		private static readonly int[] BrMpeg2L3 = new int[15]
		{
			0, 8, 16, 24, 32, 40, 48, 56, 64, 80,
			96, 112, 128, 144, 160
		};

		internal static float Duration(string path)
		{
			try
			{
				switch (Path.GetExtension(path).ToLowerInvariant())
				{
				case ".mp3":
				{
					float num2 = Mp3(path);
					if (num2 > 0.5f)
					{
						return num2;
					}
					return Ogg(path);
				}
				case ".wav":
					return Wav(path);
				default:
					return 0f;
				case ".ogg":
				case ".oga":
				case ".opus":
				{
					float num = Ogg(path);
					if (num > 0.5f)
					{
						return num;
					}
					return Mp3(path);
				}
				}
			}
			catch
			{
				return 0f;
			}
		}

		private static float Ogg(string path)
		{
			using FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
			long length = fileStream.Length;
			if (length < 1024)
			{
				return 0f;
			}
			int num = 0;
			bool flag = false;
			int num2 = (int)Math.Min(4096L, length);
			byte[] array = new byte[num2];
			fileStream.Read(array, 0, num2);
			int num3 = Find(array, num2, "vorbis", 0);
			if (num3 > 0)
			{
				if (num3 + 11 <= num2 - 4)
				{
					num = BitConverter.ToInt32(array, num3 + 11);
				}
			}
			else if (Find(array, num2, "OpusHead", 0) > 0)
			{
				flag = true;
				num = 48000;
			}
			if (num <= 0)
			{
				return 0f;
			}
			int num4 = (int)Math.Min(65536L, length);
			byte[] array2 = new byte[num4];
			fileStream.Seek(length - num4, SeekOrigin.Begin);
			fileStream.Read(array2, 0, num4);
			long num5 = 0L;
			for (int num6 = num4 - 27; num6 >= 0; num6--)
			{
				if (array2[num6] == 79 && array2[num6 + 1] == 103 && array2[num6 + 2] == 103 && array2[num6 + 3] == 83)
				{
					long num7 = BitConverter.ToInt64(array2, num6 + 6);
					if (num7 > 0)
					{
						num5 = num7;
						break;
					}
				}
			}
			if (num5 <= 0)
			{
				return 0f;
			}
			float num8 = (float)num5 / (float)num;
			if (num8 <= 0f || num8 > 7200f)
			{
				return 0f;
			}
			return flag ? ((float)num5 / 48000f) : num8;
		}

		private static int Find(byte[] buf, int len, string ascii, int from)
		{
			byte[] bytes = Encoding.ASCII.GetBytes(ascii);
			for (int i = from; i + bytes.Length <= len; i++)
			{
				bool flag = true;
				for (int j = 0; j < bytes.Length; j++)
				{
					if (buf[i + j] != bytes[j])
					{
						flag = false;
						break;
					}
				}
				if (flag)
				{
					return i;
				}
			}
			return -1;
		}

		private static float Mp3(string path)
		{
			using FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
			long length = fileStream.Length;
			if (length < 1024)
			{
				return 0f;
			}
			long num = 0L;
			byte[] array = new byte[10];
			if (fileStream.Read(array, 0, 10) == 10 && array[0] == 73 && array[1] == 68 && array[2] == 51)
			{
				int num2 = ((array[6] & 0x7F) << 21) | ((array[7] & 0x7F) << 14) | ((array[8] & 0x7F) << 7) | (array[9] & 0x7F);
				num = 10 + num2;
				if ((array[5] & 0x10) != 0)
				{
					num += 10;
				}
			}
			if (num >= length)
			{
				return 0f;
			}
			fileStream.Seek(num, SeekOrigin.Begin);
			byte[] array2 = new byte[16384];
			int num3 = fileStream.Read(array2, 0, array2.Length);
			if (num3 < 4)
			{
				return 0f;
			}
			int num4 = -1;
			int num5 = 0;
			int num6 = 0;
			int num7 = 0;
			int num8 = 0;
			for (int i = 0; i + 4 <= num3; i++)
			{
				if (array2[i] == byte.MaxValue && (array2[i + 1] & 0xE0) == 224)
				{
					int num9 = (array2[i + 1] >> 3) & 3;
					int num10 = (array2[i + 1] >> 1) & 3;
					int num11 = (array2[i + 2] >> 4) & 0xF;
					int num12 = (array2[i + 2] >> 2) & 3;
					if (num9 != 1 && num10 == 1 && num11 != 0 && num11 != 15 && num12 != 3)
					{
						int[] array3 = ((num9 == 3) ? BrMpeg1L3 : BrMpeg2L3);
						object obj = num9 switch
						{
							2 => new int[3] { 22050, 24000, 16000 }, 
							3 => new int[3] { 44100, 48000, 32000 }, 
							_ => new int[3] { 11025, 12000, 8000 }, 
						};
						num4 = i;
						num5 = num9;
						num6 = array3[num11];
						num7 = ((int[])obj)[num12];
						num8 = (array2[i + 3] >> 6) & 3;
						break;
					}
				}
			}
			if (num4 < 0 || num6 <= 0 || num7 <= 0)
			{
				return 0f;
			}
			int num13 = ((num5 == 3) ? ((num8 == 3) ? 17 : 32) : ((num8 == 3) ? 9 : 17));
			int num14 = num4 + 4 + num13;
			if (num14 + 12 <= num3)
			{
				bool num15 = array2[num14] == 88 && array2[num14 + 1] == 105 && array2[num14 + 2] == 110 && array2[num14 + 3] == 103;
				bool flag = array2[num14] == 73 && array2[num14 + 1] == 110 && array2[num14 + 2] == 102 && array2[num14 + 3] == 111;
				if ((num15 || flag) && (BitConverter.ToInt32(array2, num14 + 4) & 1) != 0)
				{
					int num16 = BitConverter.ToInt32(array2, num14 + 8);
					int num17 = ((num5 == 3) ? 1152 : 576);
					if (num16 > 0)
					{
						float num18 = (float)num16 * (float)num17 / (float)num7;
						if (num18 > 0f && num18 < 7200f)
						{
							return num18;
						}
					}
				}
			}
			float num19 = (float)(length - num - num4) * 8f / ((float)num6 * 1000f);
			if (num19 <= 0f || num19 > 7200f)
			{
				return 0f;
			}
			return num19;
		}

		private static float Wav(string path)
		{
			using FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
			byte[] array = new byte[44];
			if (fileStream.Read(array, 0, 44) < 44)
			{
				return 0f;
			}
			if (array[0] != 82 || array[1] != 73 || array[2] != 70 || array[3] != 70)
			{
				return 0f;
			}
			int num = BitConverter.ToInt32(array, 28);
			if (num <= 0)
			{
				return 0f;
			}
			return (float)(fileStream.Length - 44) / (float)num;
		}
	}
	internal static class BridgeHost
	{
		private const string FileName = "PeakNeteaseBridge.exe";

		private static string _exe;

		private static bool _tried;

		private static string _err = "";

		internal static string LastError => _err;

		internal static string Ensure()
		{
			if (_tried)
			{
				return _exe;
			}
			_tried = true;
			try
			{
				Assembly assembly = typeof(BridgeHost).Assembly;
				string text = null;
				string[] manifestResourceNames = assembly.GetManifestResourceNames();
				for (int i = 0; i < manifestResourceNames.Length; i++)
				{
					if (manifestResourceNames[i].EndsWith("PeakNeteaseBridge.exe", StringComparison.OrdinalIgnoreCase))
					{
						text = manifestResourceNames[i];
						break;
					}
				}
				if (text == null)
				{
					_err = "DLL 里没有嵌入桥接程序(构建时漏了 Native\\PeakNeteaseBridge.exe)";
					Plugin.Warn("[网易云] " + _err);
					return null;
				}
				string text2 = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "BigWalkRadioMusic", "bridge");
				string text3 = Path.Combine(text2, "PeakNeteaseBridge.exe");
				long num = -1L;
				using (Stream stream = assembly.GetManifestResourceStream(text))
				{
					if (stream != null)
					{
						try
						{
							num = stream.Length;
						}
						catch
						{
						}
					}
				}
				bool flag = false;
				try
				{
					FileInfo fileInfo = new FileInfo(text3);
					flag = fileInfo.Exists && (num <= 0 || fileInfo.Length == num);
				}
				catch
				{
				}
				if (flag)
				{
					_exe = text3;
					return _exe;
				}
				Directory.CreateDirectory(text2);
				string text4 = text3 + ".tmp";
				using (Stream stream2 = assembly.GetManifestResourceStream(text))
				{
					if (stream2 == null)
					{
						_err = "读取嵌入资源失败";
						return null;
					}
					using FileStream fileStream = new FileStream(text4, FileMode.Create, FileAccess.Write, FileShare.None);
					byte[] array = new byte[81920];
					int count;
					while ((count = stream2.Read(array, 0, array.Length)) > 0)
					{
						fileStream.Write(array, 0, count);
					}
				}
				try
				{
					if (File.Exists(text3))
					{
						File.Delete(text3);
					}
				}
				catch
				{
				}
				File.Move(text4, text3);
				_exe = text3;
				long num2 = ((num > 0) ? (num / 1048576) : 0);
				Plugin.Info("[网易云] 桥接程序已释放到 " + text3 + ((num2 > 0) ? ("(" + num2 + " MB)") : ""));
			}
			catch (Exception ex)
			{
				_err = ex.GetBaseException().Message;
				Plugin.Warn("[网易云] 释放桥接程序失败:" + _err);
				_exe = null;
			}
			return _exe;
		}

		internal static void Discard()
		{
			try
			{
				string text = Ensure();
				if (!string.IsNullOrEmpty(text) && File.Exists(text))
				{
					File.Delete(text);
				}
			}
			catch
			{
			}
			_tried = false;
			_exe = null;
		}
	}
	internal static class I18n
	{
		private static ConfigEntry<bool> _english;

		internal static bool IsEnglish
		{
			get
			{
				if (_english != null)
				{
					return _english.Value;
				}
				return false;
			}
		}

		internal static string ButtonLabel
		{
			get
			{
				if (!IsEnglish)
				{
					return "EN";
				}
				return "中文";
			}
		}

		internal static string CurrentLabel
		{
			get
			{
				if (!IsEnglish)
				{
					return "中文";
				}
				return "English";
			}
		}

		internal static void Init(ConfigFile config)
		{
			if (_english == null)
			{
				_english = config.Bind<bool>("界面/UI", "English", false, "界面语言:false=中文,true=English。也可用 F9 面板的「中/EN」按钮实时切换。");
			}
		}

		internal static string T(string zh, string en)
		{
			if (!IsEnglish)
			{
				return zh;
			}
			return en;
		}

		internal static bool Toggle()
		{
			if (_english == null)
			{
				return false;
			}
			_english.Value = !_english.Value;
			return _english.Value;
		}
	}
	internal static class LyricColors
	{
		internal static readonly string[] Names = new string[10] { "白", "暖黄", "金黄", "冰蓝", "樱粉", "薄荷", "橙", "紫", "红", "自定义" };

		internal const int Custom = 9;

		private static readonly Color[] Preset = (Color[])(object)new Color[9]
		{
			new Color(1f, 1f, 1f),
			new Color(1f, 0.851f, 0.541f),
			new Color(1f, 0.773f, 0.239f),
			new Color(0.498f, 0.847f, 1f),
			new Color(1f, 0.62f, 0.769f),
			new Color(0.486f, 0.941f, 0.722f),
			new Color(1f, 0.604f, 0.361f),
			new Color(0.753f, 0.608f, 1f),
			new Color(1f, 0.42f, 0.42f)
		};

		private static string _mainHex = "#FFFFFF";

		private static string _sungHex = "#FFD98A";

		private static Color _mainC = new Color(-1f, -1f, -1f);

		private static Color _sungC = new Color(-1f, -1f, -1f);

		internal static Color Main => LyricStyle.MainCol;

		internal static Color Sung => LyricStyle.SungCol;

		internal static bool Grad => LyricStyle.GradOn;

		internal static Color GradTo => LyricStyle.GradToCol;

		internal static string MainHex
		{
			get
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: 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_0007: 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)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				Color main = Main;
				if (main != _mainC)
				{
					_mainC = main;
					_mainHex = Hex(main);
				}
				return _mainHex;
			}
		}

		internal static string SungHex
		{
			get
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0005: 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_0007: 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)
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				Color sung = Sung;
				if (sung != _sungC)
				{
					_sungC = sung;
					_sungHex = Hex(sung);
				}
				return _sungHex;
			}
		}

		internal static Color At(int idx)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (idx < 0 || idx >= Preset.Length)
			{
				return Color.white;
			}
			return Preset[idx];
		}

		internal static Color Resolve(int idx, float r, float g, float b)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if (idx == 9)
			{
				return new Color(Mathf.Clamp01(r), Mathf.Clamp01(g), Mathf.Clamp01(b));
			}
			return At(idx);
		}

		internal static string GradBody(string text, int sung)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0038: 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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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)
			if (string.IsNullOrEmpty(text))
			{
				return "";
			}
			int length = text.Length;
			Color main = Main;
			Color gradTo = GradTo;
			StringBuilder stringBuilder = new StringBuilder(length * 24);
			for (int i = 0; i < length; i++)
			{
				Color val = ((length <= 1) ? main : Color.Lerp(main, gradTo, (float)i / (float)(length - 1)));
				float num = ((sung < 0 || i < sung) ? 1f : 0.62f);
				char c = text[i];
				switch (c)
				{
				case '<':
					c = '<';
					break;
				case '>':
					c = '>';
					break;
				}
				stringBuilder.Append("<color=").Append(Hex(new Color(val.r * num, val.g * num, val.b * num))).Append('>')
					.Append(c)
					.Append("</color>");
			}
			return stringBuilder.ToString();
		}

		internal static string Hex(Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: 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)
			int num = Mathf.Clamp(Mathf.RoundToInt(c.r * 255f), 0, 255);
			int num2 = Mathf.Clamp(Mathf.RoundToInt(c.g * 255f), 0, 255);
			int num3 = Mathf.Clamp(Mathf.RoundToInt(c.b * 255f), 0, 255);
			return "#" + num.ToString("X2") + num2.ToString("X2") + num3.ToString("X2");
		}
	}
	internal static class LyricOverlay
	{
		private sealed class Trail
		{
			public string Text;

			public Vector3 Pos;

			public int Line;

			public Vector3 RefPos;

			public float RefYaw;
		}

		private static readonly Dictionary<int, GUIStyle> _cache = new Dictionary<int, GUIStyle>();

		private static int _lastSig = -2;

		private static float _fadeAt = -10f;

		private static bool _loggedOnce;

		private static bool _errLogged;

		private static readonly List<Trail> _trail = new List<Trail>();

		private static int _trailLine = -99;

		private static string _trailSrc = "";

		private static bool UseHostRef;

		private static Vector3 _refPos;

		private static float _refYaw;

		private static Vector3 ForwardOf(float yawDeg)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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)
			float num = yawDeg * ((float)Math.PI / 180f);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(Mathf.Sin(num), 0f, Mathf.Cos(num));
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				val = Vector3.forward;
			}
			return ((Vector3)(ref val)).normalized;
		}

		private static Vector3 HostForward()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			return ForwardOf(RadioSync.HostCamYaw);
		}

		private static GUIStyle Style(int size)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			if (_cache.TryGetValue(size, out var value) && value != null)
			{
				return value;
			}
			if (_cache.Count > 120)
			{
				_cache.Clear();
			}
			value = new GUIStyle(GUI.skin.label);
			value.fontSize = Mathf.Clamp(size, 8, 96);
			value.alignment = (TextAnchor)4;
			value.richText = true;
			value.wordWrap = false;
			value.clipping = (TextClipping)0;
			value.normal.textColor = Color.white;
			_cache[size] = value;
			return value;
		}

		private static string Esc(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return "";
			}
			return s.Replace('<', '<').Replace('>', '>');
		}

		internal static void Draw()
		{
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Expected O, but got Unknown
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0361: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_0378: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0381: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			if (!LyricStyle.Show)
			{
				return;
			}
			bool flag = Lyrics.HasData && !string.IsNullOrEmpty(Lyrics.Cur);
			string text;
			if (flag)
			{
				text = Lyrics.Cur;
			}
			else
			{
				text = RadioSync.NowPlayingText;
				if (string.IsNullOrEmpty(text))
				{
					return;
				}
			}
			float unscaledTime = Time.unscaledTime;
			int hashCode = text.GetHashCode();
			if (hashCode != _lastSig)
			{
				_lastSig = hashCode;
				_fadeAt = unscaledTime;
			}
			float num = Mathf.Clamp01((unscaledTime - _fadeAt) / 0.22f);
			if (num <= 0.01f)
			{
				return;
			}
			int baseSize = Mathf.RoundToInt(LyricStyle.Size);
			string prev = (flag ? Lyrics.Prev : "");
			string text2 = (flag ? Lyrics.Next : "");
			float prog = (flag ? Lyrics.Progress : (-1f));
			bool world = LyricStyle.World;
			bool trail = LyricStyle.Trail;
			bool twoSides = LyricStyle.TwoSides;
			float offsetX = LyricStyle.OffsetX;
			if (!world)
			{
				DrawStack(prev, text, text2, (float)Screen.width * 0.5f + offsetX * 40f, (float)Screen.height * LyricStyle.Y, baseSize, 1f, num, prog);
				return;
			}
			Camera val = null;
			try
			{
				val = Camera.main;
			}
			catch
			{
			}
			if ((Object)val == (Object)null)
			{
				return;
			}
			float height = LyricStyle.Height;
			float forward = LyricStyle.Forward;
			float spread = LyricStyle.Spread;
			bool flag2 = LyricStyle.FollowView;
			UseHostRef = LyricStyle.Active && (RadioSync.HostCamValid || RadioSync.HostPoseValid);
			if (UseHostRef)
			{
				_refPos = RadioSync.HostCamPos;
				_refYaw = RadioSync.HostCamYaw;
			}
			if (!AtmosRig.HasGeometry && !UseHostRef)
			{
				flag2 = true;
			}
			if (trail)
			{
				DrawTrail(val, flag, baseSize, height, forward, num);
				return;
			}
			Vector3 val2 = default(Vector3);
			Vector3 val3;
			if (UseHostRef)
			{
				val2 = HostForward();
				val3 = (flag2 ? (RadioSync.HostCamPos + val2 * Mathf.Max(1.5f, forward) + new Vector3(0f, height * 0.35f, 0f)) : (RadioSync.HostCamPos + val2 * forward + new Vector3(0f, height, 0f)));
			}
			else if (flag2)
			{
				Transform val4 = null;
				try
				{
					val4 = ((Component)val).transform;
				}
				catch
				{
				}
				if ((Object)val4 == (Object)null)
				{
					return;
				}
				((Vector3)(ref val2))..ctor(val4.forward.x, 0f, val4.forward.z);
				if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
				{
					val2 = val4.forward;
				}
				((Vector3)(ref val2)).Normalize();
				val3 = val4.position + val2 * Mathf.Max(1.5f, forward) + new Vector3(0f, height * 0.35f, 0f);
			}
			else
			{
				float num2 = AtmosRig.Yaw * ((float)Math.PI / 180f);
				((Vector3)(ref val2))..ctor(Mathf.Sin(num2), 0f, Mathf.Cos(num2));
				val3 = AtmosRig.Center + val2 * forward + new Vector3(0f, height, 0f);
			}
			Vector3 val5 = default(Vector3);
			((Vector3)(ref val5))..ctor(val2.z, 0f, 0f - val2.x);
			if (Mathf.Abs(offsetX) > 0.001f)
			{
				val3 += val5 * offsetX;
			}
			float cx;
			float cy;
			float scale;
			if (twoSides)
			{
				DrawWorldText(val, val3 - val5 * spread, text, baseSize, num, prog, LyricColors.Main);
				if (!string.IsNullOrEmpty(text2))
				{
					DrawWorldText(val, val3 + val5 * spread, text2, baseSize, num * 0.92f, -1f, LyricColors.Main);
				}
				if (!_loggedOnce)
				{
					_loggedOnce = true;
					Plugin.Info("左右各一句歌词已就位(间距 " + spread.ToString("0.0") + "m / 前方 " + forward.ToString("0.0") + "m / 高 " + height.ToString("0.0") + "m)");
				}
			}
			else if (Project(val, val3, out cx, out cy, out scale))
			{
				DrawStack(prev, text, text2, cx, cy, baseSize, scale, num, prog);
			}
		}

		private static void DrawTrail(Camera cam, bool hasLrc, int baseSize, float h, float fwd, float alpha)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_0349: Unknown result type (might be due to invalid IL or missing references)
			//IL_034e: Unknown result type (might be due to invalid IL or missing references)
			int num = (hasLrc ? Lyrics.Index : (-1));
			string source = Lyrics.Source;
			if (source != _trailSrc)
			{
				_trail.Clear();
				_trailSrc = source;
				_trailLine = -99;
			}
			if (num < 0 && _trail.Count > 0 && !hasLrc)
			{
				_trail.Clear();
			}
			Transform val = null;
			try
			{
				val = ((Component)cam).transform;
			}
			catch
			{
			}
			if ((Object)val == (Object)null)
			{
				return;
			}
			if (hasLrc && num != _trailLine)
			{
				if (num < _trailLine)
				{
					_trail.Clear();
				}
				bool flag;
				Vector3 pos;
				Vector3 refPos;
				float refYaw;
				if (UseHostRef)
				{
					flag = RadioSync.TryAnchor(num, out var a);
					pos = a.Pos;
					refPos = a.RefPos;
					refYaw = a.RefYaw;
				}
				else
				{
					Vector3 val2 = default(Vector3);
					((Vector3)(ref val2))..ctor(val.forward.x, 0f, val.forward.z);
					if (((Vector3)(ref val2)).sqrMagnitude < 0.01f)
					{
						val2 = val.forward;
					}
					((Vector3)(ref val2)).Normalize();
					Vector3 val3 = default(Vector3);
					((Vector3)(ref val3))..ctor(val2.z, 0f, 0f - val2.x);
					pos = val.position + val2 * Mathf.Max(1.5f, fwd) + new Vector3(0f, h, 0f) + val3 * LyricStyle.OffsetX;
					refPos = val.position;
					refYaw = val.eulerAngles.y;
					flag = true;
				}
				if (!flag)
				{
					return;
				}
				_trailLine = num;
				_trail.Add(new Trail
				{
					Text = Lyrics.Cur,
					Pos = pos,
					Line = num,
					RefPos = refPos,
					RefYaw = refYaw
				});
				int trailCount = LyricStyle.TrailCount;
				while (_trail.Count > trailCount)
				{
					_trail.RemoveAt(0);
				}
				if (!_loggedOnce)
				{
					_loggedOnce = true;
					Plugin.Info("跟随生成歌词已启用:第 " + (num + 1) + " 句在前方生成锚点 (" + pos.x.ToString("0.0") + ", " + pos.y.ToString("0.0") + ", " + pos.z.ToString("0.0") + "),最多保留 " + trailCount + " 句");
				}
			}
			if (_trail.Count == 0)
			{
				return;
			}
			float num2 = _trail.Count - 1;
			for (int i = 0; i < _trail.Count; i++)
			{
				Trail trail = _trail[i];
				bool flag2 = trail.Line == num;
				float prog = (flag2 ? Lyrics.Progress : ((trail.Line < num) ? 1f : 0f));
				float num3 = ((num2 <= 0f) ? 1f : Mathf.Lerp(0.3f, 1f, (float)i / num2));
				float num4 = alpha * (flag2 ? 1f : num3);
				if (!(num4 <= 0.02f))
				{
					if (UseHostRef)
					{
						_refPos = trail.RefPos;
						_refYaw = trail.RefYaw;
					}
					DrawWorldText(cam, trail.Pos, trail.Text, baseSize, num4, prog, LyricColors.Main);
				}
			}
		}

		private static bool Project(Camera cam, Vector3 world, out float cx, out float cy, out float scale)
		{
			//IL_0017: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			cx = 0f;
			cy = 0f;
			scale = 1f;
			Vector3 val;
			try
			{
				val = cam.WorldToScreenPoint(world);
			}
			catch
			{
				return false;
			}
			if (val.z <= 0.5f)
			{
				return false;
			}
			float num = 0f;
			try
			{
				num = Vector3.Distance(((Component)cam).transform.position, world);
			}
			catch
			{
			}
			if (num < 0.05f)
			{
				return false;
			}
			scale = Mathf.Clamp(6f / num, 0.42f, 2.1f);
			cx = val.x;
			cy = (float)Screen.height - val.y;
			if (cx < -400f || cx > (float)Screen.width + 400f)
			{
				return false;
			}
			if (cy < -240f || cy > (float)Screen.height + 240f)
			{
				return false;
			}
			return true;
		}

		private static void TiltOf(Camera cam, Vector3 world, out float kx, out float sh)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0068: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: 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_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			kx = 1f;
			sh = 0f;
			float tilt = LyricStyle.Tilt;
			if (tilt <= 0.01f)
			{
				return;
			}
			Vector3 val;
			Vector3 val2;
			if (UseHostRef)
			{
				val = _refPos;
				val2 = ForwardOf(_refYaw);
			}
			else
			{
				Transform val3 = null;
				try
				{
					val3 = ((Component)cam).transform;
				}
				catch
				{
				}
				if ((Object)val3 == (Object)null)
				{
					return;
				}
				val = val3.position;
				val2 = val3.forward;
			}
			Vector3 val4 = world - val;
			val4.y = 0f;
			val2.y = 0f;
			if (!(((Vector3)(ref val4)).sqrMagnitude < 0.04f) && !(((Vector3)(ref val2)).sqrMagnitude < 0.04f))
			{
				((Vector3)(ref val4)).Normalize();
				((Vector3)(ref val2)).Normalize();
				float num = Mathf.Acos(Mathf.Clamp(Vector3.Dot(val2, val4), -1f, 1f));
				float num2 = Mathf.Max(0.28f, Mathf.Cos(num));
				float num3 = ((Vector3.Cross(val2, val4).y >= 0f) ? 1f : (-1f));
				kx = Mathf.Lerp(1f, num2, tilt);
				sh = Mathf.Lerp(0f, Mathf.Sin(num) * 0.42f * num3, tilt);
			}
		}

		private static void DrawWorldText(Camera cam, Vector3 world, string text, int baseSize, float alpha, float prog, Color col)
		{
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_010e: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(text) || !Project(cam, world, out var cx, out var cy, out var scale))
			{
				return;
			}
			int num = Mathf.Clamp(Mathf.RoundToInt((float)baseSize * scale), 9, 96);
			float num2 = Mathf.Min((float)Screen.width - 20f, 1400f);
			float num3 = (float)num * 1.42f;
			Rect r = default(Rect);
			((Rect)(ref r))..ctor(cx - num2 * 0.5f, cy - num3 * 0.5f, num2, num3);
			TiltOf(cam, world, out var kx, out var sh);
			Matrix4x4 matrix = GUI.matrix;
			bool flag = Mathf.Abs(kx - 1f) > 0.01f || Mathf.Abs(sh) > 0.005f;
			try
			{
				if (flag)
				{
					float num4 = ((Rect)(ref r)).x + ((Rect)(ref r)).width * 0.5f;
					float num5 = ((Rect)(ref r)).y + ((Rect)(ref r)).height * 0.5f;
					Matrix4x4 identity = Matrix4x4.identity;
					identity.m00 = kx;
					identity.m01 = sh;
					GUI.matrix = Matrix4x4.TRS(new Vector3(num4, num5, 0f), Quaternion.identity, Vector3.one) * identity * Matrix4x4.TRS(new Vector3(0f - num4, 0f - num5, 0f), Quaternion.identity, Vector3.one) * matrix;
				}
				Line(text, r, num, col, alpha, prog);
			}
			catch
			{
				if (!_errLogged)
				{
					_errLogged = true;
					Plugin.Warn("歌词绘制异常(已吞掉,避免刷屏)");
				}
			}
			finally
			{
				GUI.matrix = matrix;
			}
		}

		private static void DrawStack(string prev, string cur, string next, float cx, float cy, int baseSize, float scale, float alpha, float prog)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.Clamp(Mathf.RoundToInt((float)baseSize * scale), 10, 96);
			int num2 = Mathf.Max(8, Mathf.RoundToInt((float)num * 0.72f));
			float num3 = Mathf.Min((float)Screen.width - 20f, 1400f);
			float num4 = cx - num3 * 0.5f;
			float num5 = (float)num * 1.42f;
			float num6 = (float)num2 * 1.42f;
			Color main = LyricColors.Main;
			if (!string.IsNullOrEmpty(prev))
			{
				Line(prev, new Rect(num4, cy - num5 * 0.5f - num6 * 0.92f, num3, num6), num2, main, alpha * 0.55f, -1f);
			}
			Line(cur, new Rect(num4, cy - num5 * 0.5f, num3, num5), num, main, alpha, prog);
			if (!string.IsNullOrEmpty(next))
			{
				Line(next, new Rect(num4, cy + num5 * 0.5f + num6 * 0.05f, num3, num6), num2, main, alpha * 0.55f, -1f);
			}
		}

		private static void Line(string text, Rect r, int size, Color col, float alpha, float prog)
		{
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			if (alpha <= 0.01f)
			{
				return;
			}
			float num = ((Plugin.LyricBeat != null) ? Mathf.Clamp01(Plugin.LyricBeat.Value) : 0f);
			if (num > 0.001f && prog >= 0f)
			{
				float num2 = AtmosRig.Beat * num;
				if (num2 > 0.001f)
				{
					((Rect)(ref r)).y = ((Rect)(ref r)).y - num2 * (float)size * 0.34f;
					size = Mathf.Clamp(Mathf.RoundToInt((float)size * (1f + num2 * 0.11f)), 8, 96);
					alpha = Mathf.Clamp01(alpha * (1f + num2 * 0.18f));
				}
			}
			GUIStyle val = Style(size);
			string text2;
			if (LyricColors.Grad)
			{
				int sung = ((prog >= 0f) ? Mathf.Clamp(Mathf.RoundToInt(prog * (float)text.Length), 0, text.Length) : (-1));
				text2 = LyricColors.GradBody(text, sung);
			}
			else if (prog >= 0f)
			{
				int num3 = Mathf.Clamp(Mathf.RoundToInt(prog * (float)text.Length), 0, text.Length);
				string text3 = Esc(text.Substring(0, num3));
				string text4 = Esc(text.Substring(num3));
				text2 = "<color=" + LyricColors.SungHex + ">" + text3 + "</color><color=" + LyricColors.MainHex + ">" + text4 + "</color>";
			}
			else
			{
				text2 = Esc(text);
			}
			Color contentColor = GUI.contentColor;
			try
			{
				GUI.contentColor = new Color(0f, 0f, 0f, alpha * 0.72f);
				GUI.Label(new Rect(((Rect)(ref r)).x + 2f, ((Rect)(ref r)).y + 2f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text2, val);
				GUI.Label(new Rect(((Rect)(ref r)).x - 2f, ((Rect)(ref r)).y - 2f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text2, val);
				GUI.Label(new Rect(((Rect)(ref r)).x + 2f, ((Rect)(ref r)).y - 2f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text2, val);
				GUI.Label(new Rect(((Rect)(ref r)).x - 2f, ((Rect)(ref r)).y + 2f, ((Rect)(ref r)).width, ((Rect)(ref r)).height), text2, val);
				Color val2 = ((prog >= 0f || LyricColors.Grad) ? Color.white : col);
				GUI.contentColor = new Color(val2.r, val2.g, val2.b, alpha);
				GUI.Label(r, text2, val);
			}
			catch
			{
				if (!_errLogged)
				{
					_errLogged = true;
					Plugin.Warn("歌词绘制异常(已吞掉,避免刷屏)");
				}
			}
			finally
			{
				GUI.contentColor = contentColor;
			}
		}

		internal static void Reset()
		{
			_cache.Clear();
			_lastSig = -2;
			_fadeAt = -10f;
			_loggedOnce = false;
			_trail.Clear();
			_trailLine = -99;
			_trailSrc = "";
		}
	}
	internal static class Lyrics
	{
		private static string _path = "";

		private static string _stamp = "";

		private static float[] _t = new float[0];

		private static string[] _s = new string[0];

		private static float[] _plainDur = new float[0];

		private static int _idx = -1;

		private static float _time;

		private static string _lastMiss = "";

		private static string _extKey = "";

		internal static bool HasData => _s.Length != 0;

		internal static string Source => _path;

		internal static int LineCount => _s.Length;

		internal static int Index => _idx;

		internal static string Prev
		{
			get
			{
				if (_idx <= 0)
				{
					return "";
				}
				return _s[_idx - 1];
			}
		}

		internal static string Next
		{
			get
			{
				if (_idx < 0 || _idx + 1 >= _s.Length)
				{
					return "";
				}
				return _s[_idx + 1];
			}
		}

		internal static string Cur
		{
			get
			{
				if (_idx < 0 || _idx >= _s.Length)
				{
					return "";
				}
				return _s[_idx];
			}
		}

		internal static float Progress
		{
			get
			{
				if (_idx < 0 || _idx >= _s.Length)
				{
					return 0f;
				}
				float num = _t[_idx];
				float num2 = ((_idx + 1 < _t.Length) ? _t[_idx + 1] : (num + 4f));
				if (num2 <= num)
				{
					return 1f;
				}
				return Mathf.Clamp01((_time - num) / (num2 - num));
			}
		}

		internal static void Clear()
		{
			_path = "";
			_stamp = "";
			_t = new float[0];
			_s = new string[0];
			_plainDur = new float[0];
			_idx = -1;
			_time = 0f;
			_extKey = "";
		}

		internal static void Load(string audioPath)
		{
			try
			{
				if (string.IsNullOrEmpty(audioPath))
				{
					Clear();
					return;
				}
				string directoryName = Path.GetDirectoryName(audioPath);
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(audioPath);
				if (string.IsNullOrEmpty(directoryName) || string.IsNullOrEmpty(fileNameWithoutExtension))
				{
					Clear();
					return;
				}
				string text = null;
				string[] array = new string[5] { ".lrc", ".LRC", ".Lrc", ".txt", ".TXT" };
				foreach (string text2 in array)
				{
					string text3 = Path.Combine(directoryName, fileNameWithoutExtension + text2);
					if (File.Exists(text3))
					{
						text = text3;
						break;
					}
				}
				if (text == null && Plugin.LyricLoose != null && Plugin.LyricLoose.Value)
				{
					string text4 = StripIndex(fileNameWithoutExtension);
					if (text4 != fileNameWithoutExtension)
					{
						array = new string[4] { ".lrc", ".LRC", ".txt", ".TXT" };
						foreach (string text5 in array)
						{
							string text6 = Path.Combine(directoryName, text4 + text5);
							if (File.Exists(text6))
							{
								text = text6;
								break;
							}
						}
					}
					if (text == null)
					{
						List<string> list = new List<string>();
						try
						{
							array = Directory.GetFiles(directoryName, "*.*", SearchOption.TopDirectoryOnly);
							foreach (string text7 in array)
							{
								string text8 = Path.GetExtension(text7).ToLowerInvariant();
								if (text8 == ".lrc" || text8 == ".txt")
								{
									list.Add(text7);
								}
							}
						}
						catch
						{
						}
						if (list.Count == 1)
						{
							text = list[0];
						}
					}
				}
				if (text == null)
				{
					Clear();
					if (_lastMiss != fileNameWithoutExtension)
					{
						_lastMiss = fileNameWithoutExtension;
						Plugin.Info("这首没有歌词文件:找的是「" + fileNameWithoutExtension + ".lrc」(同目录放一份即可)");
					}
					return;
				}
				_lastMiss = "";
				string text9;
				try
				{
					text9 = File.GetLastWriteTime(text).Ticks + "|" + new FileInfo(text).Length;
				}
				catch
				{
					text9 = "";
				}
				if (!(text == _path) || !(text9 == _stamp))
				{
					_path = text;
					_stamp = text9;
					_idx = -1;
					Parse(File.ReadAllLines(text, Encoding.UTF8), Path.GetExtension(text).ToLowerInvariant() == ".txt");
					Plugin.Info("歌词已载入:" + Path.GetFileName(text) + "(" + _s.Length + " 句" + ((_t.Length != 0) ? ",带时间轴" : ",按行均分") + ")");
				}
			}
			catch (Exception ex)
			{
				Plugin.Warn("歌词载入失败:" + ex.GetBaseException().Message);
				Clear();
			}
		}

		private static string StripIndex(string s)
		{
			int i;
			for (i = 0; i < s.Length && char.IsDigit(s[i]); i++)
			{
			}
			if (i == 0 || i >= s.Length)
			{
				return s;
			}
			char c = s[i];
			if (c == '.' || c == '-' || c == '_' || c == ' ' || c == '、')
			{
				return s.Substring(i + 1).TrimStart('.', '-', '_', ' ');
			}
			return s;
		}

		internal static void LoadExternal(string key, List<KeyValuePair<float, string>> lines)
		{
			try
			{
				if (lines != null && lines.Count != 0 && !(key == _extKey))
				{
					Clear();
					_extKey = key;
					_t = new float[lines.Count];
					_s = new string[lines.Count];
					for (int i = 0; i < lines.Count; i++)
					{
						_t[i] = lines[i].Key;
						_s[i] = lines[i].Value;
					}
					_path = "(外部来源)";
					_stamp = key;
					Plugin.Info("外部歌词已载入:" + _s.Length + " 句(" + key + ")");
				}
			}
			catch (Exception ex)
			{
				Plugin.Warn("外部歌词载入失败:" + ex.GetBaseException().Message);
			}
		}

		internal static void ResetExternal()
		{
			_extKey = "";
		}

		private static void Parse(string[] raw, bool plain)
		{
			List<float> ts = new List<float>();
			List<string> list = new List<string>();
			if (!plain)
			{
				foreach (string text in raw)
				{
					if (string.IsNullOrEmpty(text))
					{
						continue;
					}
					List<float> list2 = new List<float>();
					int num = 0;
					while (num < text.Length && text[num] == '[')
					{
						int num2 = text.IndexOf(']', num);
						if (num2 < 0)
						{
							break;
						}
						if (TryParseTag(text.Substring(num + 1, num2 - num - 1), out var sec))
						{
							list2.Add(sec);
						}
						num = num2 + 1;
					}
					string item = ((num > 0) ? text.Substring(num).Trim() : "");
					if (list2.Count != 0)
					{
						for (int j = 0; j < list2.Count; j++)
						{
							ts.Add(list2[j]);
							list.Add(item);
						}
					}
				}
			}
			if (ts.Count == 0)
			{
				List<string> list3 = new List<string>();
				for (int k = 0; k < raw.Length; k++)
				{
					string text2 = ((raw[k] == null) ? "" : raw[k].Trim());
					if (text2.Length > 0)
					{
						list3.Add(text2);
					}
				}
				_s = list3.ToArray();
				_t = new float[0];
				_plainDur = new float[_s.Length];
				return;
			}
			int count = ts.Count;
			int[] array = new int[count];
			for (int l = 0; l < count; l++)
			{
				array[l] = l;
			}
			Array.Sort(array, delegate(int a, int b)
			{
				int num4 = ts[a].CompareTo(ts[b]);
				return (num4 == 0) ? a.CompareTo(b) : num4;
			});
			_t = new float[count];
			_s = new string[count];
			for (int num3 = 0; num3 < count; num3++)
			{
				_t[num3] = ts[array[num3]];
				_s[num3] = list[array[num3]];
			}
			_plainDur = new float[0];
		}

		private static bool TryParseTag(string tag, out float sec)
		{
			sec = 0f;
			if (string.IsNullOrEmpty(tag))
			{
				return false;
			}
			int num = tag.IndexOf(':');
			if (num <= 0)
			{
				return false;
			}
			if (!int.TryParse(tag.Substring(0, num), out var result))
			{
				return false;
			}
			if (!float.TryParse(tag.Substring(num + 1).Replace(':', ':').Replace(':', '.'), NumberStyles.Float, CultureInfo.InvariantCulture, out var result2))
			{
				return false;
			}
			sec = (float)result * 60f + result2;
			return true;
		}

		internal static void SyncToIndex(int idx)
		{
			if (_s.Length != 0 && idx >= -1 && idx < _s.Length)
			{
				_idx = idx;
			}
		}

		internal static void Tick(float time, float duration)
		{
			_time = time;
			if (_s.Length == 0)
			{
				return;
			}
			if (_t.Length == 0)
			{
				if (duration <= 0.5f || (_plainDur.Length == _s.Length && Mathf.Abs(_plainDur[0] - duration) < 0.5f && _plainDur[0] > 0f))
				{
					return;
				}
				float num = duration / (float)Mathf.Max(1, _s.Length);
				_t = new float[_s.Length];
				for (int i = 0; i < _s.Length; i++)
				{
					_t[i] = (float)i * num;
					_plainDur[i] = duration;
				}
			}
			int num2 = 0;
			int num3 = _t.Length - 1;
			int idx = -1;
			while (num2 <= num3)
			{
				int num4 = num2 + num3 >> 1;
				if (_t[num4] <= time + 0.02f)
				{
					idx = num4;
					num2 = num4 + 1;
				}
				else
				{
					num3 = num4 - 1;
				}
			}
			_idx = idx;
		}
	}
	internal static class LyricsFetcher
	{
		private enum Stage
		{
			Idle,
			Search,
			Krcs,
			Download
		}

		private struct Job
		{
			public string AudioPath;

			public string LrcPath;

			public string Title;

			public string Artist;

			public float Dur;
		}

		private sealed class Cand
		{
			public string Hash = "";

			public string Title = "";

			public string Artist = "";

			public int Dur;

			public float Score;
		}

		private static readonly HashSet<string> _tried = new HashSet<string>();

		internal static int HitCount;

		internal static int TryCount;

		private static Stage _stage = Stage.Idle;

		private static UnityWebRequest _web;

		private static float _deadline;

		private static float _nextAllowed;

		private static Job _job;

		private static int _queryStep;

		private static string _hash = "";

		private static string _status = "";

		private static string _lastUrl = "";

		private static string _lastRef = "";

		private static Stage _lastStage;

		private static int _retry;

		private static bool _retryPending;

		private static int _hit;

		private static int _try;

		private static readonly List<Job> _queue = new List<Job>();

		private static bool _autoFilled;

		private const float MinScore = 55f;

		private const float ReqTimeout = 12f;

		private const float MinGap = 0.7f;

		private const string UA = "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148";

		private static readonly string[] VerTags = new string[22]
		{
			"dj", "remix", "live", "inst", "instrumental", "cover", "acoustic", "伴奏", "纯音乐", "翻唱",
			"加速", "慢速", "女声", "男声", "8d", "环绕", "现场", "钢琴", "吉他", "抖音",
			"铃声", "合唱"
		};

		internal static string Status => _status;

		internal static bool Busy => _stage != Stage.Idle;

		internal static int QueueLength => _queue.Count;

		internal static void ResetSession()
		{
			_tried.Clear();
			_hit = 0;
			_try = 0;
		}

		internal static void Request(string audioPath, float duration)
		{
			try
			{
				if (string.IsNullOrEmpty(audioPath) || !File.Exists(audioPath))
				{
					return;
				}
				string fullPath = Path.GetFullPath(audioPath);
				string text = Path.ChangeExtension(fullPath, ".lrc");
				if (File.Exists(text) || _tried.Contains(fullPath))
				{
					return;
				}
				if (duration <= 0.5f)
				{
					duration = AudioMeta.Duration(fullPath);
				}
				if (_stage != Stage.Idle && _job.AudioPath == fullPath)
				{
					return;
				}
				for (int i = 0; i < _queue.Count; i++)
				{
					if (_queue[i].AudioPath == fullPath)
					{
						return;
					}
				}
				SplitName(Path.GetFileNameWithoutExtension(fullPath), out var artist, out var title);
				_queue.Add(new Job
				{
					AudioPath = fullPath,
					LrcPath = text,
					Title = title,
					Artist = artist,
					Dur = duration
				});
			}
			catch (Exception ex)
			{
				Plugin.Warn("排入歌词搜索失败:" + ex.GetBaseException().Message);
			}
		}

		internal static int FillAll()
		{
			int num = 0;
			try
			{
				List<string> files = RadioLibrary.Files;
				for (int i = 0; i < files.Count; i++)
				{
					string text = files[i];
					if (!File.Exists(Path.ChangeExtension(text, ".lrc")))
					{
						float duration = AudioMeta.Duration(text);
						Request(text, duration);
						num++;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Warn("批量补词失败:" + ex.GetBaseException().Message);
			}
			return num;
		}

		internal static void Tick()
		{
			try
			{
				if (!_autoFilled && Time.unscaledTime > 6f)
				{
					_autoFilled = true;
					if (Plugin.AutoFetchLyric != null && Plugin.AutoFetchLyric.Value)
					{
						int num = FillAll();
						if (num > 0)
						{
							Plugin.Info("启动自动补词:" + num + " 首缺 .lrc,已排队慢慢抓(不影响游戏)");
						}
					}
				}
				if (_stage != Stage.Idle)
				{
					Poll();
				}
				else if (!(Time.unscaledTime < _nextAllowed))
				{
					if (_retryPending && _retry < 4 && _job.AudioPath != null)
					{
						_retryPending = false;
						_retry++;
						Send(_lastUrl, _lastStage, _lastRef);
					}
					else if (_queue.Count != 0)
					{
						_job = _queue[0];
						_queue.RemoveAt(0);
						_tried.Add(_job.AudioPath);
						_queryStep = 0;
						_hash = "";
						_retry = 0;
						_retryPending = false;
						_try++;
						StartSearch();
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Warn("歌词搜索异常:" + ex.GetBaseException().Message);
				HardReset();
			}
		}

		private static void Poll()
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Invalid comparison between Unknown and I4
			if (_web == null)
			{
				HardReset();
				return;
			}
			bool flag = false;
			try
			{
				flag = _web.isDone;
			}
			catch
			{
				flag = true;
			}
			if (!flag)
			{
				if (Time.unscaledTime > _deadline)
				{
					string text = _stage.ToString();
					Dispose();
					Fail("超时(" + text + ")", giveUp: false);
				}
				return;
			}
			bool flag2 = false;
			string text2 = "";
			string text3 = "";
			long num = 0L;
			try
			{
				flag2 = (int)_web.result == 1;
				num = _web.responseCode;
				if (flag2)
				{
					text2 = ((_web.downloadHandler != null) ? _web.downloadHandler.text : "");
				}
				else
				{
					text3 = _web.error;
				}
			}
			catch (Exception ex)
			{
				text3 = ex.GetBaseException().Message;
			}
			Stage stage = _stage;
			Dispose();
			if (!flag2)
			{
				bool flag3 = num == 403 || num == 429 || num == 503 || num == 502;
				if (flag3 && _retry < 4)
				{
					_retryPending = true;
					_stage = Stage.Idle;
					_nextAllowed = Time.unscaledTime + 8f * (float)(_retry + 1);
					_status = "被限流了,等 " + 8 * (_retry + 1) + " 秒重试(第 " + (_retry + 1) + " 次)";
					Plugin.Info(_status);
				}
				else
				{
					Fail(flag3 ? "接口限流" : ("网络错误 " + text3), stage != Stage.Search);
				}
				return;
			}
			_retry = 0;
			_retryPending = false;
			switch (stage)
			{
			case Stage.Search:
				OnSearch(text2);
				break;
			case Stage.Krcs:
				OnKrcs(text2);
				break;
			case Stage.Download:
				OnDownload(text2);
				break;
			default:
				HardReset();
				break;
			}
		}

		private static void StartSearch()
		{
			string text2;
			if (_queryStep == 0 && !string.IsNullOrEmpty(_job.Artist))
			{
				string text = _job.Artist;
				int num = text.IndexOfAny(new char[4] { '/', '&', '_', '、' });
				if (num > 0)
				{
					text = text.Substring(0, num);
				}
				text2 = Bare(_job.Title) + " " + text.Trim();
			}
			else
			{
				text2 = Bare(_job.Title);
			}
			_status = "搜索歌词:" + text2;
			Send("https://mobiles.kugou.com/api/v3/search/song?format=json&keyword=" + Esc(text2) + "&page=1&pagesize=10", Stage.Search, "https://m.kugou.com/");
		}

		private static void OnSearch(string text)
		{
			List<object> list = MiniJson.List(MiniJson.Get(MiniJson.Parse(text), "data", "info"));
			Cand cand = null;
			if (list != null)
			{
				for (int i = 0; i < list.Count; i++)
				{
					Dictionary<string, object> dictionary = MiniJson.Dict(list[i]);
					if (dictionary == null)
					{
						continue;
					}
					Cand cand2 = new Cand();
					cand2.Hash = MiniJson.Str(dictionary, "hash");
					cand2.Title = MiniJson.Str(dictionary, "songname");
					cand2.Artist = MiniJson.Str(dictionary, "singername");
					cand2.Dur = (int)MiniJson.Num(dictionary, "duration");
					Cand cand3 = cand2;
					if (!string.IsNullOrEmpty(cand3.Hash) && !string.IsNullOrEmpty(cand3.Title))
					{
						cand3.Score = ScoreOf(cand3.Title, cand3.Artist, cand3.Dur, _job.Title, _job.Artist, _job.Dur);
						if (!(cand3.Score < 55f) && (cand == null || cand3.Score > cand.Score))
						{
							cand = cand3;
						}
					}
				}
			}
			if (cand == null)
			{
				if (_queryStep == 0)
				{
					_queryStep = 1;
					StartSearch();
				}
				else
				{
					Fail("没搜到匹配的歌词", giveUp: true);
				}
				return;
			}
			_hash = cand.Hash;
			_status = "找到匹配:" + cand.Artist + " - " + cand.Title + "(" + cand.Dur + "s,分 " + cand.Score.ToString("0") + ")";
			StartKrcs(cand.Dur);
		}

		private static void StartKrcs(int kgDur)
		{
			Send("https://krcs.kugou.com/search?ver=1&man=yes&client=mobi&keyword=&duration=" + kgDur * 1000 + "&hash=" + Esc(_hash), Stage.Krcs, "https://m.kugou.com/");
		}

		private static void OnKrcs(string text)
		{
			List<object> list = MiniJson.List(MiniJson.Get(MiniJson.Parse(text), "candidates"));
			if (list == null || list.Count == 0)
			{
				Fail("这首歌没有歌词", giveUp: true);
				return;
			}
			double num = (double)_job.Dur * 1000.0;
			Dictionary<string, object> dictionary = null;
			double num2 = double.MaxValue;
			for (int i = 0; i < list.Count; i++)
			{
				Dictionary<string, object> dictionary2 = MiniJson.Dict(list[i]);
				if (dictionary2 != null && !string.IsNullOrEmpty(MiniJson.Str(dictionary2, "id")) && !string.IsNullOrEmpty(MiniJson.Str(dictionary2, "accesskey")))
				{
					double num3 = MiniJson.Num(dictionary2, "duration");
					double num4 = ((num > 1.0 && num3 > 1.0) ? Math.Abs(num3 - num) : ((dictionary == null) ? 0.0 : double.MaxValue));
					if (dictionary == null || num4 < num2)
					{
						dictionary = dictionary2;
						num2 = num4;
					}
					if (num > 1.0 && num3 > 1.0 && Math.Abs(num3 - num) < 1200.0)
					{
						break;
					}
				}
			}
			if (dictionary == null)
			{
				Fail("歌词候选都不可用", giveUp: true);
				return;
			}
			string s = MiniJson.Str(dictionary, "id");
			string s2 = MiniJson.Str(dictionary, "accesskey");
			Send("https://lyrics.kugou.com/download?ver=1&client=pc&id=" + Esc(s) + "&accesskey=" + Esc(s2) + "&fmt=lrc&charset=utf8", Stage.Download, "https://krcs.kugou.com/");
		}

		private static void OnDownload(string text)
		{
			string text2 = MiniJson.Str(MiniJson.Parse(text), "content");
			if (string.IsNullOrEmpty(text2))
			{
				Fail("歌词内容为空", giveUp: true);
				return;
			}
			string text3;
			try
			{
				byte[] bytes = Convert.FromBase64String(text2);
				text3 = Encoding.UTF8.GetString(bytes);
				if (text3.Length > 0 && text3[0] == '\ufeff')
				{
					text3 = text3.Substring(1);
				}
			}
			catch
			{
				Fail("歌词解码失败", giveUp: true);
				return;
			}
			if (!Meaningful(text3))
			{
				Fail("歌词是纯音乐/空词", giveUp: true);
				return;
			}
			try
			{
				string directoryName = Path.GetDirectoryName(_job.LrcPath);
				if (!string.IsNullOrEmpty(directoryName) && !Directory.Exists(directoryName))
				{
					Directory.CreateDirectory(directoryName);
				}
				File.WriteAllText(_job.LrcPath, text3, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));
			}
			catch (Exception ex)
			{
				Fail("写歌词文件失败 " + ex.GetBaseException().Message, giveUp: true);
				return;
			}
			_hit++;
			HitCount = _hit;
			TryCount = _try;
			_status = "已写入歌词:" + Path.GetFileName(_job.LrcPath) + "(" + CountLines(text3) + " 行)";
			Plugin.Info(_status);
			try
			{
				string currentPath = RadioSync.CurrentPath;
				if (!string.IsNullOrEmpty(currentPath) && Path.GetFullPath(currentPath) == _job.AudioPath)
				{
					Lyrics.Load(_job.AudioPath);
				}
			}
			catch
			{
			}
			_stage = Stage.Idle;
			_web = null;
			_nextAllowed = Time.unscaledTime + 0.7f;
		}

		private static int TagMask(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return 0;
			}
			string text = s.ToLowerInvariant();
			int num = 0;
			for (int i = 0; i < VerTags.Length && i < 31; i++)
			{
				if (text.IndexOf(VerTags[i], StringComparison.Ordinal) >= 0)
				{
					num |= 1 << i;
				}
			}
			return num;
		}

		private static float ScoreOf(string kTitle, string kArtist, int kDur, string title, string artist, float dur)
		{
			string text = Norm(title);
			string text2 = Norm(kTitle);
			if (text2.Length == 0 || text.Length == 0)
			{
				return -1f;
			}
			float num;
			if (text2 == text)
			{
				num = 60f;
			}
			else
			{
				if (text2.IndexOf(text, StringComparison.Ordinal) < 0 && text.IndexOf(text2, StringComparison.Ordinal) < 0)
				{
					return -1f;
				}
				num = 26f;
			}
			string text3 = Norm(artist);
			string text4 = Norm(kArtist);
			if (text3.Length > 0)
			{
				if (text4.Length > 0 && text4 == text3)
				{
					num += 25f;
				}
				else if (text4.Length > 0 && (text4.IndexOf(text3, StringComparison.Ordinal) >= 0 || text3.IndexOf(text4, StringComparison.Ordinal) >= 0))
				{
					num += 14f;
				}
				else
				{
					bool flag = false;
					string[] array = artist.Split('/', '&', '_', '、', ',', ',');
					for (int i = 0; i < array.Length; i++)
					{
						string text5 = Norm(array[i]);
						if (text5.Length >= 2 && text4.IndexOf(text5, StringComparison.Ordinal) >= 0)
						{
							flag = true;
							break;
						}
					}
					if (flag)
					{
						num += 8f;
					}
				}
			}
			if (dur > 1f && kDur > 1)
			{
				float num2 = Mathf.Abs(dur - (float)kDur);
				if (num2 <= 2f)
				{
					num += 30f;
				}
				else if (num2 <= 5f)
				{
					num += 22f;
				}
				else if (num2 <= 10f)
				{
					num += 12f;
				}
				else
				{
					if (!(num2 <= 20f))
					{
						return -1f;
					}
					num += 4f;
				}
			}
			int num3 = TagMask(title);
			int num4 = TagMask(kTitle);
			if (num3 == 0 && num4 != 0)
			{
				return -1f;
			}
			if (num3 != 0 && num4 == 0)
			{
				return -1f;
			}
			if (num3 != 0 && num4 != 0 && (num3 & num4) == 0)
			{
				return -1f;
			}
			if (num3 != 0 && (num3 & num4) != 0)
			{
				num += 8f;
			}
			return num;
		}

		private static string Norm(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return "";
			}
			StringBuilder stringBuilder = new StringBuilder(s.Length);
			bool flag = false;
			foreach (char c in s)
			{
				switch (c)
				{
				case '(':
				case '[':
				case '{':
				case '【':
				case '(':
					flag = true;
					continue;
				case ')':
				case ']':
				case '}':
				case '】':
				case ')':
					flag = false;
					continue;
				}
				if (!flag && !char.IsWhiteSpace(c) && !char.IsPunctuation(c) && !char.IsSymbol(c))
				{
					stringBuilder.Append(char.ToLowerInvariant(c));
				}
			}
			return stringBuilder.ToString();
		}

		private static string Bare(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return "";
			}
			int num = 0;
			StringBuilder stringBuilder = new StringBuilder(s.Length);
			foreach (char c in s)
			{
				switch (c)
				{
				case '(':
				case '[':
				case '【':
				case '(':
					num++;
					break;
				case ')':
				case ']':
				case '】':
				case ')':
					if (num > 0)
					{
						num--;
					}
					break;
				default:
					if (num <= 0)
					{
						stringBuilder.Append(c);
					}
					break;
				}
			}
			string text = stringBuilder.ToString().Trim();
			if (text.Length <= 0)
			{
				return s.Trim();
			}
			return text;
		}

		private static void SplitName(string stem, out string artist, out string title)
		{
			artist = "";
			title = stem ?? "";
			if (string.IsNullOrEmpty(stem))
			{
				return;
			}
			int num = stem.IndexOf(" - ", StringComparison.Ordinal);
			if (num > 0)
			{
				artist = stem.Substring(0, num).Replace(" _ ", " / ").Trim();
				title = stem.Substring(num + 3).Trim();
				return;
			}
			int i;
			for (i = 0; i < stem.Length && char.IsDigit(stem[i]); i++)
			{
			}
			if (i > 0 && i < stem.Length)
			{
				char c = stem[i];
				if (c == '.' || c == '-' || c == '_' || c == ' ' || c == '、')
				{
					title = stem.Substring(i + 1).Trim();
				}
			}
		}

		private static bool Meaningful(string lrc)
		{
			if (string.IsNullOrEmpty(lrc))
			{
				return false;
			}
			int num = 0;
			bool flag = false;
			foreach (char c in lrc)
			{
				switch (c)
				{
				case '[':
					flag = true;
					continue;
				case ']':
					flag = false;
					continue;
				}
				if (!flag && !char.IsWhiteSpace(c))
				{
					num++;
				}
			}
			if (num < 6)
			{
				return false;
			}
			if (lrc.IndexOf("纯音乐", StringComparison.Ordinal) >= 0 && num < 40)
			{
				return false;
			}
			return true;
		}

		private static int CountLines(string s)
		{
			int num = 1;
			for (int i = 0; i < s.Length; i++)
			{
				if (s[i] == '\n')
				{
					num++;
				}
			}
			return num;
		}

		private static string Esc(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return "";
			}
			byte[] bytes = Encoding.UTF8.GetBytes(s);
			StringBuilder stringBuilder = new StringBuilder(bytes.Length * 3);
			for (int i = 0; i < bytes.Length; i++)
			{
				byte b = bytes[i];
				if ((b >= 97 && b <= 122) || (b >= 65 && b <= 90) || (b >= 48 && b <= 57) || b == 45 || b == 95 || b == 46 || b == 126)
				{
					stringBuilder.Append((char)b);
				}
				else
				{
					stringBuilder.Append('%').Append(b.ToString("X2"));
				}
			}
			return stringBuilder.ToString();
		}

		private static void Send(string url, Stage stage, string referer)
		{
			Dispose();
			_stage = stage;
			_lastUrl = url;
			_lastStage = stage;
			_lastRef = referer;
			_deadline = Time.unscaledTime + 12f;
			try
			{
				UnityWebRequest obj = UnityWebRequest.Get(url);
				obj.timeout = 12;
				obj.SetRequestHeader("User-Agent", "Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X) AppleWebKit/605.1.15 Mobile/15E148");
				obj.SetRequestHeader("Referer", referer);
				obj.SetRequestHeader("Accept", "*/*");
				obj.SendWebRequest();
				_web = obj;
			}
			catch (Exception ex)
			{
				Plugin.Warn("发起歌词请求失败:" + ex.GetBaseException().Message);
				Fail("请求失败", giveUp: true);
			}
		}

		private static void Dispose()
		{
			if (_web != null)
			{
				try
				{
					_web.Dispose();
				}
				catch
				{
				}
				_web = null;
			}
		}

		private static void Fail(string why, bool giveUp)
		{
			Dispose();
			_stage = Stage.Idle;
			_nextAllowed = Time.unscaledTime + 0.7f;
			_web = null;
			_retryPending = false;
			_retry = 0;
			if (giveUp)
			{
				if (why.IndexOf("网络", StringComparison.Ordinal) >= 0 || why.IndexOf("限流", StringComparison.Ordinal) >= 0 || why.IndexOf("超时", StringComparison.Ordinal) >= 0)
				{
					_tried.Remove(_job.AudioPath);
				}
				else
				{
					_try--;
				}
				TryCount = _try;
				_status = "没找到:" + Path.GetFileNameWithoutExtension(_job.AudioPath) + "(" + why + ")";
				Plugin.Info("自动搜歌词失败:" + Path.GetFileName(_job.AudioPath) + " → " + why);
			}
		}

		private static void HardReset()
		{
			Dispose();
			_stage = Stage.Idle;
			_web = null;
		}
	}
	internal static class LyricStyle
	{
		internal sealed class Snapshot
		{
			internal bool Show;

			internal bool World;

			internal bool TwoSides;

			internal bool Trail;

			internal bool FollowView;

			internal bool Grad;

			internal int TrailCount;

			internal float Y;

			internal float Size;

			internal float Height;

			internal float Forward;

			internal float Spread;

			internal float Tilt;

			internal float OffsetX;

			internal Color Main;

			internal Color Sung;

			internal Color GradTo;

			internal int Bits
			{
				get
				{
					int num = 0;
					if (Show)
					{
						num |= 1;
					}
					if (World)
					{
						num |= 2;
					}
					if (TwoSides)
					{
						num |= 4;
					}
					if (Trail)
					{
						num |= 8;
					}
					if (FollowView)
					{
						num |= 0x10;
					}
					if (Grad)
					{
						num |= 0x20;
					}
					return num;
				}
			}

			internal int Hash()
			{
				//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bc: 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)
				return (((((((((((17 * 31 + Bits) * 31 + TrailCount) * 31 + Mathf.RoundToInt(Y * 1000f)) * 31 + Mathf.RoundToInt(Size