Decompiled source of Song Player v0.2.1

SongPlayer.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MPTK.NAudio.Midi;
using Microsoft.CodeAnalysis;
using MidiPlayerTK;
using OnTogetherMods.Shared;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SongPlayer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.1.0")]
[assembly: AssemblyInformationalVersion("0.2.1+622bd7ccbb267719684ff770ce18e1834dc51b45")]
[assembly: AssemblyProduct("SongPlayer")]
[assembly: AssemblyTitle("SongPlayer")]
[assembly: AssemblyVersion("0.2.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace OnTogetherMods.Shared
{
	internal static class PanelStack
	{
		private const string TableKey = "OnTogetherMods.PanelStack.Panels";

		private const string HiddenKey = "OnTogetherMods.PanelStack.Hidden";

		private const string IconBarKey = "OnTogetherMods.IconBar.Rect";

		private const float Margin = 20f;

		private const float FromRight = 0.15f;

		private const float Gap = 10f;

		private const int WorldScene = 2;

		public const int PhotoModeOrder = 0;

		public const int EmoteSyncOrder = 10;

		public const int TeleportSpotsOrder = 20;

		public const int SongPlayerOrder = 30;

		public const int TraceOverlayOrder = 40;

		public const int NameDesignerOrder = 50;

		public const string CanvasPrefix = "OnTogetherMods ";

		private static int _deskFrame = -1;

		private static bool _desk;

		public static float Width => (float)Screen.width * 1080f / (float)Screen.height;

		public static bool Hidden
		{
			get
			{
				if (!(AppDomain.CurrentDomain.GetData("OnTogetherMods.PanelStack.Hidden") is int num) || Time.frameCount > num)
				{
					return InDeskMode;
				}
				return true;
			}
		}

		public static bool InDeskMode
		{
			get
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: Invalid comparison between Unknown and I4
				int frameCount = Time.frameCount;
				if (_deskFrame != frameCount)
				{
					_deskFrame = frameCount;
					_desk = false;
					Scene activeScene = SceneManager.GetActiveScene();
					if (((Scene)(ref activeScene)).buildIndex == 2)
					{
						OverlayManager i = MonoSingleton<OverlayManager>.I;
						_desk = (Object)(object)i != (Object)null && (int)i.ResolutionMode == 3;
					}
				}
				return _desk;
			}
		}

		public static bool IsModCanvas(Canvas canvas)
		{
			Canvas val = canvas;
			Transform parent = ((Component)canvas).transform.parent;
			while ((Object)(object)parent != (Object)null)
			{
				Canvas component = ((Component)parent).GetComponent<Canvas>();
				val = (((Object)(object)component != (Object)null) ? component : val);
				parent = parent.parent;
			}
			return ((Object)((Component)val).gameObject).name.StartsWith("OnTogetherMods ", StringComparison.Ordinal);
		}

		public static void HideForCapture()
		{
			AppDomain.CurrentDomain.SetData("OnTogetherMods.PanelStack.Hidden", Time.frameCount + 1);
		}

		public static Rect Place(string id, int order, Vector2 size)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			Hashtable hashtable = Panels();
			int frameCount = Time.frameCount;
			hashtable[id] = new double[3] { order, size.y, frameCount };
			float width = Width;
			float num = Mathf.Max(20f, width * 0.85f - size.x);
			float num2 = Bottom(num + size.x, frameCount) - size.y;
			foreach (DictionaryEntry item in hashtable)
			{
				string text = (string)item.Key;
				double[] array = (double[])item.Value;
				bool flag = (double)frameCount - array[2] <= 2.0;
				bool flag2 = array[0] < (double)order || (array[0] == (double)order && string.CompareOrdinal(text, id) < 0);
				if (text != id && flag && flag2)
				{
					num2 -= (float)array[1] + 10f;
				}
			}
			return new Rect(num, num2, size.x, size.y);
		}

		private static float Bottom(float windowRight, int frame)
		{
			float num = 1060f;
			if (AppDomain.CurrentDomain.GetData("OnTogetherMods.IconBar.Rect") is double[] array && (double)frame - array[4] <= 2.0)
			{
				float num2 = 1080f / (float)Screen.height;
				if (array[0] * (double)num2 < (double)(windowRight + 10f))
				{
					num = Mathf.Min(num, (float)array[1] * num2 - 10f);
				}
			}
			return num;
		}

		public static Matrix4x4 Begin(out float width)
		{
			//IL_000d: 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)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)Screen.height / 1080f;
			Matrix4x4 matrix = GUI.matrix;
			GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
			width = (float)Screen.width / num;
			return matrix;
		}

		public static void End(Matrix4x4 previous)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			GUI.matrix = previous;
		}

		public static GUIStyle MakeStyle(TextAnchor alignment)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.box)
			{
				alignment = alignment,
				fontSize = 15,
				richText = true,
				wordWrap = false,
				padding = new RectOffset(12, 12, 10, 10)
			};
			val.normal.textColor = Color.white;
			return val;
		}

		private static Hashtable Panels()
		{
			Hashtable hashtable = AppDomain.CurrentDomain.GetData("OnTogetherMods.PanelStack.Panels") as Hashtable;
			if (hashtable == null)
			{
				hashtable = new Hashtable();
				AppDomain.CurrentDomain.SetData("OnTogetherMods.PanelStack.Panels", hashtable);
			}
			return hashtable;
		}
	}
	internal static class IconBar
	{
		public enum State
		{
			Plain,
			Open,
			On,
			Off
		}

		public enum Click
		{
			None,
			Left,
			Right
		}

		private struct Metrics
		{
			public float Unit;

			public int Art;

			public int Button;

			public int Gap;

			public int Margin;
		}

		private static class Patches
		{
			private static Action<InputManager, bool> _setMouse0Down;

			private static Action<InputManager, bool> _setMouse1;

			private static Action<InputManager, bool> _setMouse1Up;

			private static FieldRef<QuadPainterGPU, Vector2> _previousUV;

			private static bool _leftOnBar;

			private static bool _rightOnBar;

			public static void Apply(Harmony harmony)
			{
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_0062: Expected O, but got Unknown
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a7: Expected O, but got Unknown
				_setMouse0Down = Setter("IsMouseButton0Down");
				_setMouse1 = Setter("IsMouseButton1");
				_setMouse1Up = Setter("IsMouseButton1Up");
				harmony.Patch((MethodBase)AccessTools.Method(typeof(InputManager), "Update", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(Patches), "InputPostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				_previousUV = AccessTools.FieldRefAccess<QuadPainterGPU, Vector2>("previousUV");
				harmony.Patch((MethodBase)AccessTools.Method(typeof(QuadPainterGPU), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Patches), "PaintPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}

			private static void InputPostfix(InputManager __instance)
			{
				bool mouseOver = MouseOver;
				if (Input.GetMouseButtonDown(0))
				{
					_leftOnBar = mouseOver;
				}
				if (Input.GetMouseButtonDown(1))
				{
					_rightOnBar = mouseOver;
				}
				if (mouseOver)
				{
					_setMouse0Down(__instance, arg2: false);
				}
				if (_rightOnBar)
				{
					_setMouse1(__instance, arg2: false);
					_setMouse1Up(__instance, arg2: false);
				}
				if (!Input.GetMouseButton(0))
				{
					_leftOnBar = false;
				}
				if (!Input.GetMouseButton(1))
				{
					_rightOnBar = false;
				}
			}

			private static bool PaintPrefix(QuadPainterGPU __instance)
			{
				if (__instance.IsActive && (_leftOnBar || MouseOver))
				{
					_previousUV.Invoke(__instance).x = -1f;
					return false;
				}
				return true;
			}

			private static Action<InputManager, bool> Setter(string property)
			{
				return (Action<InputManager, bool>)Delegate.CreateDelegate(typeof(Action<InputManager, bool>), AccessTools.PropertySetter(typeof(InputManager), property));
			}
		}

		public const int PhotoModeOrder = 0;

		public const int EmoteSyncOrder = 10;

		public const int TeleportSpotsOrder = 20;

		public const int NameDesignerOrder = 30;

		public const int DeskSnapOrder = 40;

		public const int FocusAnywhereOrder = 50;

		public const int SongPlayerOrder = 60;

		public const int TraceOverlayOrder = 70;

		public const int ChatRangeOrder = 80;

		private const string RectKey = "OnTogetherMods.IconBar.Rect";

		private const string TableKey = "OnTogetherMods.IconBar.Icons";

		private const string PatchedKey = "OnTogetherMods.IconBar.Patched";

		private const string BlockerKey = "OnTogetherMods.IconBar.Blocker";

		private const string BlockerFrameKey = "OnTogetherMods.IconBar.BlockerFrame";

		private const string HiddenKey = "OnTogetherMods.IconBar.HiddenUntil";

		private const int WorldScene = 2;

		private const int TooltipDepth = -100;

		private static readonly Dictionary<char, Color32> Palette = new Dictionary<char, Color32>
		{
			{
				'K',
				new Color32((byte)42, (byte)36, (byte)51, byte.MaxValue)
			},
			{
				'W',
				new Color32((byte)247, (byte)243, (byte)234, byte.MaxValue)
			},
			{
				'G',
				new Color32((byte)201, (byte)198, (byte)207, byte.MaxValue)
			},
			{
				'g',
				new Color32((byte)143, (byte)138, (byte)153, byte.MaxValue)
			},
			{
				'D',
				new Color32((byte)87, (byte)82, (byte)95, byte.MaxValue)
			},
			{
				'B',
				new Color32((byte)168, (byte)107, (byte)60, byte.MaxValue)
			},
			{
				'b',
				new Color32((byte)217, (byte)160, (byte)102, byte.MaxValue)
			},
			{
				'd',
				new Color32((byte)110, (byte)67, (byte)37, byte.MaxValue)
			},
			{
				'R',
				new Color32((byte)224, (byte)90, (byte)90, byte.MaxValue)
			},
			{
				'r',
				new Color32((byte)168, (byte)58, (byte)70, byte.MaxValue)
			},
			{
				'p',
				new Color32((byte)246, (byte)165, (byte)165, byte.MaxValue)
			},
			{
				'Y',
				new Color32((byte)245, (byte)208, (byte)97, byte.MaxValue)
			},
			{
				'y',
				new Color32((byte)201, (byte)150, (byte)50, byte.MaxValue)
			},
			{
				'O',
				new Color32((byte)232, (byte)146, (byte)74, byte.MaxValue)
			},
			{
				'L',
				new Color32((byte)159, (byte)214, (byte)245, byte.MaxValue)
			},
			{
				'U',
				new Color32((byte)74, (byte)143, (byte)217, byte.MaxValue)
			},
			{
				'u',
				new Color32((byte)47, (byte)90, (byte)158, byte.MaxValue)
			},
			{
				'N',
				new Color32((byte)116, (byte)192, (byte)105, byte.MaxValue)
			},
			{
				'n',
				new Color32((byte)63, (byte)138, (byte)74, byte.MaxValue)
			},
			{
				'P',
				new Color32((byte)246, (byte)207, (byte)174, byte.MaxValue)
			},
			{
				'V',
				new Color32((byte)154, (byte)114, (byte)214, byte.MaxValue)
			},
			{
				'v',
				new Color32((byte)105, (byte)72, (byte)160, byte.MaxValue)
			},
			{
				'S',
				new Color32((byte)233, (byte)139, (byte)181, byte.MaxValue)
			},
			{
				'H',
				new Color32((byte)60, (byte)48, (byte)56, byte.MaxValue)
			}
		};

		private static readonly Color32 ButtonFill = new Color32((byte)28, (byte)26, (byte)34, (byte)200);

		private static readonly Color32 ButtonEdge = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)30);

		private static readonly Color32 HoverFill = new Color32((byte)48, (byte)45, (byte)58, (byte)225);

		private static readonly Color32 HoverEdge = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)80);

		private static readonly Color32 OpenFill = new Color32((byte)70, (byte)64, (byte)88, (byte)235);

		private static readonly Color32 OpenEdge = new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)150);

		private static readonly Color32 DotFill = new Color32((byte)140, (byte)220, (byte)120, byte.MaxValue);

		private static readonly Color32 DotEdge = new Color32((byte)20, (byte)40, (byte)20, byte.MaxValue);

		private static readonly Dictionary<string[], Texture2D[]> Icons = new Dictionary<string[], Texture2D[]>();

		private static Texture2D _buttonTexture;

		private static Texture2D _hoverTexture;

		private static Texture2D _openTexture;

		private static Texture2D _dotTexture;

		private static GUIStyle _buttonStyle;

		private static GUIStyle _tipStyle;

		private static int _builtFor;

		private static int _cachedFrame = -1;

		private static bool _inWorld;

		private static bool _visible;

		private static int _pressedButton;

		private static bool RowHidden
		{
			get
			{
				if (AppDomain.CurrentDomain.GetData("OnTogetherMods.IconBar.HiddenUntil") is int num)
				{
					return Time.frameCount <= num;
				}
				return false;
			}
		}

		public static bool MouseOver
		{
			get
			{
				//IL_003d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: 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_006f: Unknown result type (might be due to invalid IL or missing references)
				if (!(AppDomain.CurrentDomain.GetData("OnTogetherMods.IconBar.Rect") is double[] array) || array[5] < 0.5 || (double)Time.frameCount - array[4] > 2.0)
				{
					return false;
				}
				Vector3 mousePosition = Input.mousePosition;
				Rect val = default(Rect);
				((Rect)(ref val))..ctor((float)array[0], (float)array[1], (float)array[2], (float)array[3]);
				return ((Rect)(ref val)).Contains(new Vector2(mousePosition.x, (float)Screen.height - mousePosition.y));
			}
		}

		public static Click Draw(string id, int order, string[] pixels, State state, string name, KeyCode key, string hint = null)
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0023: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			int controlID = GUIUtility.GetControlID((FocusType)2);
			Event current = Event.current;
			Refresh();
			if (!_inWorld)
			{
				Hide(controlID, current);
				UpdateBlocker(shown: false, default(Rect));
				return Click.None;
			}
			Rect bar;
			Metrics m;
			Rect icon = Place(id, order, out bar, out m);
			Share(bar);
			UpdateBlocker(_visible, bar);
			if (!_visible)
			{
				Hide(controlID, current);
				return Click.None;
			}
			Matrix4x4 matrix = GUI.matrix;
			GUI.matrix = Matrix4x4.identity;
			try
			{
				return Handle(controlID, current, icon, m, pixels, state, name, key, hint);
			}
			finally
			{
				GUI.matrix = matrix;
			}
		}

		public static void HideRow()
		{
			AppDomain.CurrentDomain.SetData("OnTogetherMods.IconBar.HiddenUntil", Time.frameCount + 1);
		}

		public static string KeyText(KeyCode key)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if ((int)key != 0)
			{
				return $" ({key})";
			}
			return "";
		}

		private static Click Handle(int control, Event e, Rect icon, Metrics m, string[] pixels, State state, string name, KeyCode key, string hint)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected I4, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0100: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: 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)
			bool flag = ((Rect)(ref icon)).Contains(e.mousePosition);
			EventType typeForControl = e.GetTypeForControl(control);
			switch ((int)typeForControl)
			{
			default:
			{
				if ((int)typeForControl != 7)
				{
					break;
				}
				BuildStyles(m);
				bool flag2 = GUIUtility.hotControl == control;
				_buttonStyle.normal.background = ((state == State.Open || (flag2 && flag)) ? _openTexture : (flag ? _hoverTexture : _buttonTexture));
				_buttonStyle.Draw(icon, false, false, false, false);
				Texture2D[] array = IconTextures(pixels);
				GUI.DrawTexture(new Rect(((Rect)(ref icon)).x + (((Rect)(ref icon)).width - (float)m.Art) / 2f, ((Rect)(ref icon)).y + (((Rect)(ref icon)).height - (float)m.Art) / 2f, (float)m.Art, (float)m.Art), (Texture)(object)((state == State.Off) ? array[1] : array[0]));
				if (state == State.On)
				{
					float num = Mathf.Max(1, Mathf.RoundToInt(2f * m.Unit));
					float num2 = ((Texture)_dotTexture).width;
					GUI.DrawTexture(new Rect(((Rect)(ref icon)).xMax - num - num2, ((Rect)(ref icon)).yMax - num - num2, num2, num2), (Texture)(object)_dotTexture);
				}
				int num3;
				if (flag)
				{
					num3 = ((GUIUtility.hotControl == 0 || flag2) ? 1 : 0);
					if (num3 != 0)
					{
						DrawTooltip(icon, m, Tooltip(state, name, key, hint));
					}
				}
				else
				{
					num3 = 0;
				}
				GUI.depth = ((num3 != 0) ? (-100) : 0);
				break;
			}
			case 0:
				if (flag && (e.button == 0 || e.button == 1))
				{
					GUIUtility.hotControl = control;
					_pressedButton = e.button;
					e.Use();
				}
				break;
			case 3:
				if (GUIUtility.hotControl == control)
				{
					e.Use();
				}
				break;
			case 1:
				if (GUIUtility.hotControl != control)
				{
					break;
				}
				GUIUtility.hotControl = 0;
				e.Use();
				if (flag && e.button == _pressedButton)
				{
					if (e.button != 0)
					{
						return Click.Right;
					}
					return Click.Left;
				}
				break;
			case 2:
				break;
			}
			return Click.None;
		}

		private static string Tooltip(State state, string name, KeyCode key, string hint)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			string text = name + KeyText(key);
			switch (state)
			{
			case State.On:
				text += ": on";
				break;
			case State.Off:
				text += ": off";
				break;
			}
			if (hint == null)
			{
				return text;
			}
			return text + "\n" + hint;
		}

		private static void DrawTooltip(Rect icon, Metrics m, string text)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			GUIContent val = new GUIContent(text);
			Vector2 val2 = _tipStyle.CalcSize(val);
			float num = Mathf.Clamp(((Rect)(ref icon)).center.x - val2.x / 2f, (float)m.Margin, Mathf.Max((float)m.Margin, (float)(Screen.width - m.Margin) - val2.x));
			float num2 = ((Rect)(ref icon)).y - (float)m.Gap - val2.y;
			_tipStyle.Draw(new Rect(Mathf.Round(num), Mathf.Round(num2), val2.x, val2.y), val, false, false, false, false);
		}

		private static void Hide(int control, Event e)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			if (GUIUtility.hotControl == control)
			{
				GUIUtility.hotControl = 0;
			}
			if ((int)e.type == 7)
			{
				GUI.depth = 0;
			}
		}

		private static Metrics Measure()
		{
			float num = (float)Screen.height / 1080f;
			int num2 = Mathf.Max(1, Mathf.RoundToInt(2f * num));
			int num3 = Mathf.Max(2, Mathf.RoundToInt(4f * num));
			return new Metrics
			{
				Unit = num,
				Art = 16 * num2,
				Button = 16 * num2 + 2 * num3,
				Gap = Mathf.Max(2, Mathf.RoundToInt(6f * num)),
				Margin = Mathf.RoundToInt(20f * num)
			};
		}

		private static Rect Place(string id, int order, out Rect bar, out Metrics m)
		{
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			Hashtable hashtable = Table();
			int frameCount = Time.frameCount;
			if (hashtable[id] is double[] array)
			{
				array[0] = order;
				array[1] = frameCount;
			}
			else
			{
				hashtable[id] = new double[2] { order, frameCount };
			}
			int num = 0;
			int num2 = 0;
			foreach (DictionaryEntry item in hashtable)
			{
				string text = (string)item.Key;
				double[] array2 = (double[])item.Value;
				if (!((double)frameCount - array2[1] > 2.0))
				{
					num2++;
					if (text != id && (array2[0] < (double)order || (array2[0] == (double)order && string.CompareOrdinal(text, id) < 0)))
					{
						num++;
					}
				}
			}
			m = Measure();
			int num3 = num2 * m.Button + (num2 - 1) * m.Gap;
			int num4 = Screen.width - m.Margin - num3;
			int num5 = Screen.height - m.Margin - m.Button;
			bar = new Rect((float)num4, (float)num5, (float)num3, (float)m.Button);
			return new Rect((float)(num4 + num * (m.Button + m.Gap)), (float)num5, (float)m.Button, (float)m.Button);
		}

		private static void Share(Rect bar)
		{
			AppDomain currentDomain = AppDomain.CurrentDomain;
			int frameCount = Time.frameCount;
			if (!(currentDomain.GetData("OnTogetherMods.IconBar.Rect") is double[] array) || (int)array[4] != frameCount || !(array[2] >= (double)((Rect)(ref bar)).width))
			{
				currentDomain.SetData("OnTogetherMods.IconBar.Rect", new double[6]
				{
					((Rect)(ref bar)).x,
					((Rect)(ref bar)).y,
					((Rect)(ref bar)).width,
					((Rect)(ref bar)).height,
					frameCount,
					_visible ? 1 : 0
				});
			}
		}

		private static Hashtable Table()
		{
			Hashtable hashtable = AppDomain.CurrentDomain.GetData("OnTogetherMods.IconBar.Icons") as Hashtable;
			if (hashtable == null)
			{
				hashtable = new Hashtable();
				AppDomain.CurrentDomain.SetData("OnTogetherMods.IconBar.Icons", hashtable);
			}
			return hashtable;
		}

		private static void Refresh()
		{
			//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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Invalid comparison between Unknown and I4
			int frameCount = Time.frameCount;
			if (_cachedFrame != frameCount)
			{
				_cachedFrame = frameCount;
				Scene activeScene = SceneManager.GetActiveScene();
				_inWorld = ((Scene)(ref activeScene)).buildIndex == 2;
				_visible = false;
				if (_inWorld && !PanelStack.Hidden && !RowHidden)
				{
					TaskManager i = MonoSingleton<TaskManager>.I;
					_visible = (Object)(object)i != (Object)null && ((int)i.LockState == 0 || (int)i.LockState == 5);
				}
			}
		}

		private static void UpdateBlocker(bool shown, Rect bar)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Expected O, but got Unknown
			//IL_00a4: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			AppDomain currentDomain = AppDomain.CurrentDomain;
			int frameCount = Time.frameCount;
			if (currentDomain.GetData("OnTogetherMods.IconBar.BlockerFrame") is int num && num == frameCount)
			{
				return;
			}
			currentDomain.SetData("OnTogetherMods.IconBar.BlockerFrame", frameCount);
			object? data = currentDomain.GetData("OnTogetherMods.IconBar.Blocker");
			GameObject val = (GameObject)((data is GameObject) ? data : null);
			if ((Object)(object)val == (Object)null)
			{
				if (!shown)
				{
					return;
				}
				val = CreateBlocker();
				currentDomain.SetData("OnTogetherMods.IconBar.Blocker", val);
			}
			if (shown)
			{
				RectTransform val2 = (RectTransform)val.transform.GetChild(0);
				Vector2 val3 = default(Vector2);
				((Vector2)(ref val3))..ctor(((Rect)(ref bar)).x, (float)Screen.height - ((Rect)(ref bar)).yMax);
				if (val2.anchoredPosition != val3)
				{
					val2.anchoredPosition = val3;
				}
				if (val2.sizeDelta != ((Rect)(ref bar)).size)
				{
					val2.sizeDelta = ((Rect)(ref bar)).size;
				}
			}
			if (val.activeSelf != shown)
			{
				val.SetActive(shown);
			}
		}

		private static GameObject CreateBlocker()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//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_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("OnTogetherMods IconBar ClickBlocker");
			Object.DontDestroyOnLoad((Object)(object)val);
			Canvas obj = val.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 32767;
			val.AddComponent<GraphicRaycaster>();
			GameObject val2 = new GameObject("Area", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val2.transform.SetParent(val.transform, false);
			((Graphic)val2.GetComponent<Image>()).color = Color.clear;
			RectTransform val3 = (RectTransform)val2.transform;
			val3.anchorMin = Vector2.zero;
			val3.anchorMax = Vector2.zero;
			val3.pivot = Vector2.zero;
			val.SetActive(false);
			return val;
		}

		public static void Patch()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			AppDomain currentDomain = AppDomain.CurrentDomain;
			if (currentDomain.GetData("OnTogetherMods.IconBar.Patched") != null)
			{
				return;
			}
			currentDomain.SetData("OnTogetherMods.IconBar.Patched", true);
			try
			{
				Patches.Apply(new Harmony("nelphei.ontogether.iconbar"));
			}
			catch (Exception arg)
			{
				Debug.LogError((object)$"[OnTogetherMods] Icon bar patches failed, so clicks on it may reach the game: {arg}");
			}
		}

		private static Texture2D[] IconTextures(string[] pixels)
		{
			//IL_0093: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: 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)
			if (Icons.TryGetValue(pixels, out var value) && (Object)(object)value[0] != (Object)null && (Object)(object)value[1] != (Object)null)
			{
				return value;
			}
			Color32[] array = (Color32[])(object)new Color32[256];
			Color32[] array2 = (Color32[])(object)new Color32[256];
			for (int i = 0; i < 16; i++)
			{
				string text = ((i < pixels.Length) ? pixels[i] : "");
				for (int j = 0; j < 16; j++)
				{
					char key = ((j < text.Length) ? text[j] : '.');
					Color32 value2;
					Color32 val = (Color32)(Palette.TryGetValue(key, out value2) ? value2 : new Color32((byte)0, (byte)0, (byte)0, (byte)0));
					int num = (15 - i) * 16 + j;
					array[num] = val;
					byte b = (byte)Mathf.RoundToInt(0.3f * (float)(int)val.r + 0.59f * (float)(int)val.g + 0.11f * (float)(int)val.b);
					array2[num] = new Color32(b, b, b, (byte)((float)(int)val.a * 0.45f));
				}
			}
			value = (Texture2D[])(object)new Texture2D[2]
			{
				NewTexture(16, 16, array, (FilterMode)0),
				NewTexture(16, 16, array2, (FilterMode)0)
			};
			Icons[pixels] = value;
			return value;
		}

		private static void BuildStyles(Metrics m)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Expected O, but got Unknown
			//IL_0105: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			if (_builtFor != Screen.height || _buttonStyle == null || !((Object)(object)_buttonTexture != (Object)null) || !((Object)(object)_dotTexture != (Object)null))
			{
				_builtFor = Screen.height;
				int num = Mathf.Max(2, Mathf.RoundToInt(6f * m.Unit));
				Destroy(_buttonTexture);
				Destroy(_hoverTexture);
				Destroy(_openTexture);
				Destroy(_dotTexture);
				_buttonTexture = RoundedBox(num, ButtonFill, ButtonEdge);
				_hoverTexture = RoundedBox(num, HoverFill, HoverEdge);
				_openTexture = RoundedBox(num, OpenFill, OpenEdge);
				int num2 = Mathf.Max(2, Mathf.RoundToInt(3f * m.Unit));
				_dotTexture = RoundedBox(num2, DotFill, DotEdge, 2 * num2);
				int num3 = num + 1;
				_buttonStyle = new GUIStyle
				{
					border = new RectOffset(num3, num3, num3, num3)
				};
				_tipStyle = new GUIStyle
				{
					border = new RectOffset(num3, num3, num3, num3),
					padding = new RectOffset(Mathf.RoundToInt(10f * m.Unit), Mathf.RoundToInt(10f * m.Unit), Mathf.RoundToInt(6f * m.Unit), Mathf.RoundToInt(6f * m.Unit)),
					fontSize = Mathf.Max(8, Mathf.RoundToInt(15f * m.Unit)),
					alignment = (TextAnchor)3,
					wordWrap = false,
					richText = false
				};
				_tipStyle.normal.background = _hoverTexture;
				_tipStyle.normal.textColor = Color.white;
			}
		}

		private static Texture2D RoundedBox(int radius, Color32 fill, Color32 edge, int size = 0)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			if (size <= 0)
			{
				size = 2 * radius + 4;
			}
			Color32[] array = (Color32[])(object)new Color32[size * size];
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num = (float)j + 0.5f;
					float num2 = (float)i + 0.5f;
					float num3 = Mathf.Max(Mathf.Max((float)radius - num, num - (float)(size - radius)), 0f);
					float num4 = Mathf.Max(Mathf.Max((float)radius - num2, num2 - (float)(size - radius)), 0f);
					float num5 = Mathf.Sqrt(num3 * num3 + num4 * num4) - (float)radius;
					float num6 = Mathf.Clamp01(0.5f - num5);
					Color val = Color.Lerp(Color32.op_Implicit(fill), Color32.op_Implicit(edge), Mathf.Clamp01(num5 + 1.5f));
					val.a *= num6;
					array[i * size + j] = Color32.op_Implicit(val);
				}
			}
			return NewTexture(size, size, array, (FilterMode)1);
		}

		private static Texture2D NewTexture(int width, int height, Color32[] pixels, FilterMode filter)
		{
			//IL_0004: 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_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			Texture2D val = new Texture2D(width, height, (TextureFormat)4, false)
			{
				filterMode = filter,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61
			};
			val.SetPixels32(pixels);
			val.Apply(false, true);
			return val;
		}

		private static void Destroy(Texture2D texture)
		{
			if ((Object)(object)texture != (Object)null)
			{
				Object.Destroy((Object)(object)texture);
			}
		}
	}
	internal sealed class ClickBlocker
	{
		private readonly GameObject _root;

		private readonly RectTransform _area;

		public ClickBlocker(string name)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Expected O, but got Unknown
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			_root = new GameObject(name);
			Object.DontDestroyOnLoad((Object)(object)_root);
			Canvas obj = _root.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 32767;
			_root.AddComponent<GraphicRaycaster>();
			GameObject val = new GameObject("Area", new Type[3]
			{
				typeof(RectTransform),
				typeof(CanvasRenderer),
				typeof(Image)
			});
			val.transform.SetParent(_root.transform, false);
			((Graphic)val.GetComponent<Image>()).color = Color.clear;
			_area = (RectTransform)val.transform;
			_area.anchorMin = Vector2.zero;
			_area.anchorMax = Vector2.zero;
			_area.pivot = Vector2.zero;
			_root.SetActive(false);
		}

		public void Update(bool shown, Rect screenRect)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_root == (Object)null))
			{
				if (shown)
				{
					_area.anchoredPosition = new Vector2(((Rect)(ref screenRect)).x, (float)Screen.height - ((Rect)(ref screenRect)).yMax);
					_area.sizeDelta = ((Rect)(ref screenRect)).size;
				}
				if (_root.activeSelf != shown)
				{
					_root.SetActive(shown);
				}
			}
		}

		public void Destroy()
		{
			if ((Object)(object)_root != (Object)null)
			{
				Object.Destroy((Object)(object)_root);
			}
		}

		public static bool MouseIn(Rect screenRect)
		{
			//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_0008: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 mousePosition = Input.mousePosition;
			return ((Rect)(ref screenRect)).Contains(new Vector2(mousePosition.x, (float)Screen.height - mousePosition.y));
		}
	}
}
namespace SongPlayer
{
	internal static class Icon
	{
		public static readonly string[] Pixels = new string[16]
		{
			"................", "................", ".....KKKKKKKKKK.", ".....KYYYYYYYYK.", ".....KYYYYYYYYK.", ".....KYKKKKKKYK.", ".....KYK....KYK.", ".....KYK....KYK.", ".....KYK....KYK.", ".....KYK....KYK.",
			"..KKKKYK.KKKKYK.", ".KWYYYYKKWYYYYK.", ".KYYYYyKKYYYYyK.", "..KKKKK..KKKKK..", "................", "................"
		};
	}
	[HarmonyPatch(typeof(MusicManager), "EquipInstrument")]
	internal static class EquipInstrumentPatch
	{
		private static void Postfix(MusicManager __instance)
		{
			SongWindow.Music = __instance;
		}
	}
	[HarmonyPatch(typeof(InputManager), "Update")]
	internal static class InputPatch
	{
		private static readonly Action<InputManager, bool> SetMouse0Down = (Action<InputManager, bool>)Delegate.CreateDelegate(typeof(Action<InputManager, bool>), AccessTools.PropertySetter(typeof(InputManager), "IsMouseButton0Down"));

		private static void Postfix(InputManager __instance)
		{
			if (SongWindow.IsMouseOver)
			{
				SetMouse0Down(__instance, arg2: false);
			}
		}
	}
	internal sealed class Performer
	{
		public const int KeyCount = 13;

		private static readonly FieldRef<MusicManager, List<int>> OctaveShifts = AccessTools.FieldRefAccess<MusicManager, List<int>>("_octaveShifts");

		private static readonly FieldRef<MusicManager, List<int>> MinOctaves = AccessTools.FieldRefAccess<MusicManager, List<int>>("_minOctaves");

		private static readonly FieldRef<MusicManager, List<int>> MaxOctaves = AccessTools.FieldRefAccess<MusicManager, List<int>>("_maxOctaves");

		private static readonly Dictionary<int, int[]> DrumStandIns = new Dictionary<int, int[]>
		{
			{
				35,
				new int[1] { 36 }
			},
			{
				36,
				new int[1] { 35 }
			},
			{
				37,
				new int[2] { 38, 40 }
			},
			{
				38,
				new int[1] { 40 }
			},
			{
				39,
				new int[2] { 38, 40 }
			},
			{
				40,
				new int[1] { 38 }
			},
			{
				41,
				new int[2] { 43, 45 }
			},
			{
				43,
				new int[2] { 41, 45 }
			},
			{
				45,
				new int[2] { 47, 43 }
			},
			{
				47,
				new int[2] { 45, 48 }
			},
			{
				48,
				new int[2] { 47, 50 }
			},
			{
				50,
				new int[2] { 48, 47 }
			},
			{
				42,
				new int[2] { 44, 46 }
			},
			{
				44,
				new int[2] { 42, 46 }
			},
			{
				46,
				new int[2] { 42, 44 }
			},
			{
				49,
				new int[3] { 57, 46, 42 }
			},
			{
				57,
				new int[3] { 49, 46, 42 }
			},
			{
				52,
				new int[3] { 49, 57, 46 }
			},
			{
				55,
				new int[3] { 49, 57, 46 }
			},
			{
				51,
				new int[3] { 59, 53, 42 }
			},
			{
				53,
				new int[3] { 51, 59, 42 }
			},
			{
				59,
				new int[3] { 51, 53, 42 }
			}
		};

		private readonly float[] _heldUntil = new float[13];

		private MusicManager _music;

		private InstrumentType _instrument;

		private List<SongNote> _notes;

		private int _next;

		private double _startTime;

		private int _lowest;

		public bool IsPlaying => _notes != null;

		public float PositionMs
		{
			get
			{
				if (!IsPlaying)
				{
					return 0f;
				}
				return (float)((Time.realtimeSinceStartupAsDouble - _startTime) * 1000.0);
			}
		}

		public Performer()
		{
			ClearKeys();
		}

		public void Play(MusicManager music, InstrumentType instrument, List<SongNote> notes, float fromMs)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Invalid comparison between Unknown and I4
			Stop();
			_music = music;
			_instrument = instrument;
			_lowest = (((int)instrument == 2) ? CurrentShift() : MoveToBestOctave(notes));
			_next = 0;
			while (_next < notes.Count && notes[_next].Start < fromMs)
			{
				_next++;
			}
			_notes = notes;
			_startTime = Time.realtimeSinceStartupAsDouble - (double)fromMs / 1000.0;
		}

		public void Stop()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_music != (Object)null)
			{
				for (int i = 0; i < 13; i++)
				{
					if (_heldUntil[i] >= 0f)
					{
						_music.StopNoteMaster(i, _instrument);
					}
				}
			}
			Forget();
		}

		public void Forget()
		{
			ClearKeys();
			_notes = null;
			_music = null;
		}

		public bool Tick(int maxNotesAtOnce)
		{
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			if (!IsPlaying)
			{
				return false;
			}
			float positionMs = PositionMs;
			_lowest = CurrentShift();
			for (int i = 0; i < 13; i++)
			{
				if (_heldUntil[i] >= 0f && _heldUntil[i] <= positionMs)
				{
					_music.StopNoteMaster(i, _instrument);
					_heldUntil[i] = -1f;
				}
			}
			while (_next < _notes.Count && _notes[_next].Start <= positionMs)
			{
				SongNote songNote = _notes[_next++];
				if (songNote.End <= positionMs)
				{
					continue;
				}
				int num = KeyFor(songNote.Pitch);
				if (num >= 0)
				{
					if (_heldUntil[num] >= 0f)
					{
						_music.StopNoteMaster(num, _instrument);
					}
					else if (HeldCount() >= maxNotesAtOnce)
					{
						continue;
					}
					_music.PlayNoteMaster(num, _instrument);
					_heldUntil[num] = songNote.End;
				}
			}
			if (_next >= _notes.Count && HeldCount() == 0)
			{
				Forget();
				return false;
			}
			return true;
		}

		private int KeyFor(int pitch)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			if ((int)_instrument == 2)
			{
				int num = pitch - _lowest;
				if (num >= 0 && num < 13)
				{
					return num;
				}
				if (DrumStandIns.TryGetValue(pitch, out var value))
				{
					int[] array = value;
					for (int i = 0; i < array.Length; i++)
					{
						num = array[i] - _lowest;
						if (num >= 0 && num < 13)
						{
							return num;
						}
					}
				}
				return -1;
			}
			int j;
			for (j = pitch - _lowest; j < 0; j += 12)
			{
			}
			while (j >= 13)
			{
				j -= 12;
			}
			return j;
		}

		private int MoveToBestOctave(List<SongNote> notes)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected I4, but got Unknown
			int index = (int)_instrument;
			List<int> list = OctaveShifts.Invoke(_music);
			int current = list[index];
			int num = MinOctaves.Invoke(_music)[index];
			int num2 = MaxOctaves.Invoke(_music)[index];
			int best = current;
			int bestCount = Fits(notes, current);
			for (int num3 = current - 12; num3 >= num; num3 -= 12)
			{
				Consider(num3);
			}
			for (int i = current + 12; i <= num2; i += 12)
			{
				Consider(i);
			}
			for (int j = 0; j < 10; j++)
			{
				if (list[index] >= best)
				{
					break;
				}
				_music.ShiftOctaveUpMaster();
			}
			for (int k = 0; k < 10; k++)
			{
				if (list[index] <= best)
				{
					break;
				}
				_music.ShiftOctaveDownMaster();
			}
			return CurrentShift();
			void Consider(int lowest)
			{
				int num4 = Fits(notes, lowest);
				if (num4 > bestCount || (num4 == bestCount && Mathf.Abs(lowest - current) < Mathf.Abs(best - current)))
				{
					best = lowest;
					bestCount = num4;
				}
			}
		}

		private int CurrentShift()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected I4, but got Unknown
			return OctaveShifts.Invoke(_music)[(int)_instrument];
		}

		private static int Fits(List<SongNote> notes, int lowest)
		{
			int num = 0;
			foreach (SongNote note in notes)
			{
				if (note.Pitch >= lowest && note.Pitch < lowest + 13)
				{
					num++;
				}
			}
			return num;
		}

		private int HeldCount()
		{
			int num = 0;
			for (int i = 0; i < 13; i++)
			{
				if (_heldUntil[i] >= 0f)
				{
					num++;
				}
			}
			return num;
		}

		private void ClearKeys()
		{
			for (int i = 0; i < 13; i++)
			{
				_heldUntil[i] = -1f;
			}
		}
	}
	[BepInPlugin("nelphei.ontogether.songplayer", "Song Player", "0.2.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "nelphei.ontogether.songplayer";

		public const string PluginName = "Song Player";

		public const string PluginVersion = "0.2.1";

		internal static ManualLogSource Log;

		internal static Settings Settings;

		private GameObject _host;

		private void Awake()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Settings = new Settings(((BaseUnityPlugin)this).Config);
			new Harmony("nelphei.ontogether.songplayer").PatchAll();
			IconBar.Patch();
			_host = new GameObject("SongPlayer");
			((Object)_host).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)_host);
			_host.AddComponent<SongWindow>();
			Log.LogInfo((object)("Song Player 0.2.1 loaded. Sit at an instrument to open the song list. Songs folder: " + Settings.Folder()));
		}

		private void OnDestroy()
		{
			if ((Object)(object)_host != (Object)null)
			{
				Object.Destroy((Object)(object)_host);
			}
		}
	}
	internal sealed class Settings
	{
		public readonly ConfigEntry<bool> Enabled;

		public readonly ConfigEntry<string> SongFolder;

		public readonly ConfigEntry<int> MaxNotesAtOnce;

		public readonly ConfigEntry<int> VisibleRows;

		public readonly ConfigEntry<bool> ShowIcon;

		public Settings(ConfigFile config)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Expected O, but got Unknown
			Enabled = config.Bind<bool>("Songs", "Enabled", true, "Show the song window when you sit at an instrument. The mod's icon at the bottom-right switches this on and off, and it's remembered between games. Switching it off stops a song that's playing.");
			SongFolder = config.Bind<string>("Songs", "SongFolder", "", "Folder the song list reads .mid files from. Leave empty to use Music\\On-Together.");
			MaxNotesAtOnce = config.Bind<int>("Songs", "MaxNotesAtOnce", 6, new ConfigDescription("The most keys held down at the same time. Extra notes in big chords are skipped, which keeps busy songs from sounding muddy.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 13), Array.Empty<object>()));
			VisibleRows = config.Bind<int>("Display", "VisibleRows", 6, new ConfigDescription("How many songs the window shows before it scrolls.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(3, 15), Array.Empty<object>()));
			ShowIcon = config.Bind<bool>("Display", "ShowIcon", true, "Show a music notes icon in the row of mod icons at the bottom-right, with a green dot while Enabled is on. Clicking it switches Enabled.");
		}

		public string Folder()
		{
			string text = SongFolder.Value;
			if (string.IsNullOrWhiteSpace(text))
			{
				string text2 = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
				if (string.IsNullOrEmpty(text2))
				{
					text2 = Application.persistentDataPath;
				}
				text = Path.Combine(text2, "On-Together");
			}
			return text;
		}
	}
	internal struct SongNote
	{
		public float Start;

		public float End;

		public int Pitch;

		public int Channel;
	}
	internal sealed class SongPart
	{
		public string Label;

		public List<SongNote> Notes;
	}
	internal sealed class Song
	{
		public const int DrumChannel = 9;

		private const float MinNoteMs = 60f;

		private const float ChordMs = 30f;

		public string Name;

		public float LengthMs;

		public List<SongPart> MelodicParts = new List<SongPart>();

		public SongPart DrumPart;

		public static Song Load(string path, out string error)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Invalid comparison between Unknown and I4
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Invalid comparison between Unknown and I4
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Invalid comparison between Unknown and I4
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Invalid comparison between Unknown and I4
			error = null;
			MidiLoad val = new MidiLoad();
			if (!val.MPTK_Load(File.ReadAllBytes(path), false) || val.MPTK_MidiEvents == null)
			{
				error = "isn't a MIDI file the game can read";
				return null;
			}
			List<SongNote> list = new List<SongNote>();
			Dictionary<int, long> dictionary = new Dictionary<int, long>();
			Dictionary<long, string> dictionary2 = new Dictionary<long, string>();
			Dictionary<int, int> dictionary3 = new Dictionary<int, int>();
			foreach (MPTKEvent mPTK_MidiEvent in val.MPTK_MidiEvents)
			{
				if ((int)mPTK_MidiEvent.Command == 144 && mPTK_MidiEvent.Velocity > 0)
				{
					list.Add(new SongNote
					{
						Start = mPTK_MidiEvent.RealTime,
						End = mPTK_MidiEvent.RealTime + Math.Max(mPTK_MidiEvent.Duration, 60f),
						Pitch = mPTK_MidiEvent.Value,
						Channel = mPTK_MidiEvent.Channel
					});
					if (!dictionary.ContainsKey(mPTK_MidiEvent.Channel))
					{
						dictionary[mPTK_MidiEvent.Channel] = mPTK_MidiEvent.Track;
					}
				}
				else if ((int)mPTK_MidiEvent.Command == 255 && (int)mPTK_MidiEvent.Meta == 3 && !string.IsNullOrWhiteSpace(mPTK_MidiEvent.Info) && !dictionary2.ContainsKey(mPTK_MidiEvent.Track))
				{
					dictionary2[mPTK_MidiEvent.Track] = mPTK_MidiEvent.Info.Trim();
				}
				else if ((int)mPTK_MidiEvent.Command == 192 && !dictionary3.ContainsKey(mPTK_MidiEvent.Channel))
				{
					dictionary3[mPTK_MidiEvent.Channel] = mPTK_MidiEvent.Value;
				}
			}
			if (list.Count == 0)
			{
				error = "has no notes";
				return null;
			}
			list.Sort((SongNote a, SongNote b) => a.Start.CompareTo(b.Start));
			float start = list[0].Start;
			float num = 0f;
			for (int num2 = 0; num2 < list.Count; num2++)
			{
				SongNote value = list[num2];
				value.Start -= start;
				value.End -= start;
				list[num2] = value;
				num = Math.Max(num, value.End);
			}
			Song song = new Song
			{
				Name = Path.GetFileNameWithoutExtension(path),
				LengthMs = num
			};
			List<SongNote> list2 = list.Where((SongNote n) => n.Channel == 9).ToList();
			if (list2.Count > 0)
			{
				song.DrumPart = new SongPart
				{
					Label = "Drums",
					Notes = list2
				};
			}
			List<SongNote> list3 = list.Where((SongNote n) => n.Channel != 9).ToList();
			if (list3.Count > 0)
			{
				song.MelodicParts.Add(new SongPart
				{
					Label = "All parts",
					Notes = list3
				});
				song.MelodicParts.Add(new SongPart
				{
					Label = "Melody only",
					Notes = Melody(list3)
				});
				List<int> list4 = (from c in list3.Select((SongNote n) => n.Channel).Distinct()
					orderby c
					select c).ToList();
				if (list4.Count > 1)
				{
					foreach (int channel in list4)
					{
						song.MelodicParts.Add(new SongPart
						{
							Label = PartName(channel, dictionary, dictionary2, dictionary3),
							Notes = list3.Where((SongNote n) => n.Channel == channel).ToList()
						});
					}
				}
			}
			return song;
		}

		private static List<SongNote> Melody(List<SongNote> notes)
		{
			List<SongNote> list = new List<SongNote>();
			int num = 0;
			while (num < notes.Count)
			{
				SongNote item = notes[num];
				int i;
				for (i = num + 1; i < notes.Count && notes[i].Start - notes[num].Start <= 30f; i++)
				{
					if (notes[i].Pitch > item.Pitch)
					{
						item = notes[i];
					}
				}
				list.Add(item);
				num = i;
			}
			for (int j = 0; j + 1 < list.Count; j++)
			{
				SongNote value = list[j];
				value.End = Math.Max(value.Start + 60f, Math.Min(value.End, list[j + 1].Start));
				list[j] = value;
			}
			return list;
		}

		private static string PartName(int channel, Dictionary<int, long> trackOf, Dictionary<long, string> trackNames, Dictionary<int, int> programs)
		{
			if (trackOf.TryGetValue(channel, out var value) && trackNames.TryGetValue(value, out var value2))
			{
				return value2;
			}
			if (programs.TryGetValue(channel, out var value3))
			{
				try
				{
					return PatchChangeEvent.GetPatchName(value3);
				}
				catch (Exception)
				{
				}
			}
			return "Channel " + (channel + 1);
		}
	}
	internal sealed class SongWindow : MonoBehaviour
	{
		private const string PanelId = "SongPlayer";

		private const float Width = 360f;

		private const float Pad = 10f;

		private const float HeaderHeight = 24f;

		private const float RowHeight = 30f;

		private const float Gap = 4f;

		private const float ProgressHeight = 22f;

		private const float StatusHeight = 22f;

		private const float ScrollbarWidth = 16f;

		private const float StatusSeconds = 5f;

		private static readonly FieldRef<MusicManager, MusicInstrumentController> CurrentInstrument = AccessTools.FieldRefAccess<MusicManager, MusicInstrumentController>("_currentInstrument");

		private static SongWindow _instance;

		internal static MusicManager Music;

		private readonly Performer _performer = new Performer();

		private readonly List<string> _files = new List<string>();

		private bool _active;

		private bool _iconClicked;

		private InstrumentType _instrument;

		private Song _song;

		private string _songPath;

		private int _partIndex;

		private Vector2 _scroll;

		private string _status;

		private float _statusUntil;

		private Rect _screenRect;

		private int _drawnFrame = -100;

		private ClickBlocker _blocker;

		private GUIStyle _boxStyle;

		private GUIStyle _titleStyle;

		private GUIStyle _instrumentStyle;

		private GUIStyle _buttonStyle;

		private GUIStyle _songStyle;

		private GUIStyle _playingStyle;

		private GUIStyle _emptyStyle;

		private GUIStyle _timeStyle;

		private GUIStyle _statusStyle;

		private GUIStyle _tipStyle;

		internal static bool IsMouseOver { get; private set; }

		private static Settings S => Plugin.Settings;

		private void Awake()
		{
			_instance = this;
			_blocker = new ClickBlocker("SongPlayer ClickBlocker");
		}

		private void OnDestroy()
		{
			if ((Object)(object)_instance == (Object)(object)this)
			{
				_instance = null;
				IsMouseOver = false;
			}
			_blocker?.Destroy();
		}

		private void Update()
		{
			try
			{
				if (_iconClicked)
				{
					_iconClicked = false;
					S.Enabled.Value = !S.Enabled.Value;
				}
				bool flag = (Object)(object)Music != (Object)null && Music.IsActive;
				bool flag2 = flag && S.Enabled.Value;
				if (flag2 && !_active)
				{
					SitDown();
				}
				else if (!flag2 && _active)
				{
					if (flag)
					{
						_performer.Stop();
					}
					StandUp();
				}
				if (_active && _performer.IsPlaying && !_performer.Tick(S.MaxNotesAtOnce.Value))
				{
					Status("Finished " + _song.Name);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
				_performer.Forget();
				Status("Something went wrong. See the BepInEx log.");
			}
			UpdateMouseOver();
		}

		private void SitDown()
		{
			//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)
			MusicInstrumentController val = CurrentInstrument.Invoke(Music);
			if (!((Object)(object)val == (Object)null))
			{
				_active = true;
				_instrument = val.musicInstrumentType;
				_partIndex = 0;
				_status = null;
				RefreshList();
			}
		}

		private void StandUp()
		{
			_active = false;
			_performer.Forget();
		}

		private void UpdateMouseOver()
		{
			//IL_0022: 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)
			bool flag = _active && Time.frameCount - _drawnFrame <= 2;
			IsMouseOver = flag && ClickBlocker.MouseIn(_screenRect);
			_blocker?.Update(flag, _screenRect);
		}

		private void RefreshList()
		{
			_files.Clear();
			string path = S.Folder();
			try
			{
				if (Directory.Exists(path))
				{
					_files.AddRange((from f in Directory.GetFiles(path)
						where f.EndsWith(".mid", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".midi", StringComparison.OrdinalIgnoreCase)
						select f).OrderBy<string, string>((string f) => Path.GetFileName(f), StringComparer.OrdinalIgnoreCase));
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
				Status("Couldn't read the songs folder. See the BepInEx log.");
			}
		}

		private void OpenFolder()
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			string text = S.Folder();
			try
			{
				Directory.CreateDirectory(text);
				if ((int)Application.platform == 2)
				{
					Process.Start("explorer.exe", "\"" + text + "\"");
				}
				else
				{
					Application.OpenURL(new Uri(text).AbsoluteUri);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)ex);
				Status("Couldn't open " + text);
			}
		}

		private void PlayFile(string path)
		{
			if (path != _songPath || _song == null)
			{
				Song song;
				string error;
				try
				{
					song = Song.Load(path, out error);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)ex);
					song = null;
					error = "couldn't be opened";
				}
				if (song == null)
				{
					Status(Path.GetFileNameWithoutExtension(path) + " " + error);
					return;
				}
				_song = song;
				_songPath = path;
				_partIndex = 0;
			}
			StartPart(0f);
		}

		private void StartPart(float fromMs)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			List<SongPart> list = Parts();
			if (list.Count == 0)
			{
				_performer.Stop();
				Status(((int)_instrument == 2) ? (_song.Name + " has no drums. Try another instrument.") : (_song.Name + " only has drums. Try the drum kit."));
			}
			else
			{
				_partIndex = Mathf.Clamp(_partIndex, 0, list.Count - 1);
				_performer.Play(Music, _instrument, list[_partIndex].Notes, fromMs);
				_status = null;
			}
		}

		private void NextPart()
		{
			List<SongPart> list = Parts();
			if (list.Count >= 2)
			{
				_partIndex = (_partIndex + 1) % list.Count;
				if (_performer.IsPlaying)
				{
					StartPart(_performer.PositionMs);
				}
			}
		}

		private List<SongPart> Parts()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			if (_song == null)
			{
				return new List<SongPart>();
			}
			if ((int)_instrument == 2)
			{
				if (_song.DrumPart == null)
				{
					return new List<SongPart>();
				}
				return new List<SongPart> { _song.DrumPart };
			}
			return _song.MelodicParts;
		}

		private void Status(string text)
		{
			_status = text;
			_statusUntil = Time.unscaledTime + 5f;
		}

		private void OnGUI()
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			if (S.ShowIcon.Value && IconBar.Draw("SongPlayer", 60, Icon.Pixels, S.Enabled.Value ? IconBar.State.On : IconBar.State.Off, "Song Player", (KeyCode)0, "Shows the song list at instruments") == IconBar.Click.Left)
			{
				_iconClicked = true;
			}
			if (!_active || PanelStack.Hidden)
			{
				return;
			}
			if (_boxStyle == null)
			{
				MakeStyles();
			}
			float width;
			Matrix4x4 previous = PanelStack.Begin(out width);
			try
			{
				DrawWindow();
			}
			catch (Exception ex) when (!(ex is ExitGUIException))
			{
				Plugin.Log.LogError((object)ex);
			}
			finally
			{
				PanelStack.End(previous);
			}
		}

		private void DrawWindow()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: 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)
			int num = Mathf.Clamp(_files.Count, 2, S.VisibleRows.Value);
			float num2 = (float)num * 30f + (float)(num - 1) * 4f;
			float num3 = 38f + num2 + 8f + 30f + 4f + 22f + 4f + 30f + 4f + 22f + 10f;
			Rect val = PanelStack.Place("SongPlayer", 30, new Vector2(360f, num3));
			float num4 = (float)Screen.height / 1080f;
			_screenRect = new Rect(((Rect)(ref val)).x * num4, ((Rect)(ref val)).y * num4, ((Rect)(ref val)).width * num4, ((Rect)(ref val)).height * num4);
			_drawnFrame = Time.frameCount;
			GUI.Box(val, GUIContent.none, _boxStyle);
			float num5 = ((Rect)(ref val)).x + 10f;
			float num6 = ((Rect)(ref val)).width - 20f;
			float num7 = ((Rect)(ref val)).y + 10f;
			GUI.Label(new Rect(num5, num7, num6, 24f), "<b>SONG PLAYER</b>", _titleStyle);
			GUI.Label(new Rect(num5, num7, num6, 24f), InstrumentName(_instrument), _instrumentStyle);
			num7 += 28f;
			DrawList(new Rect(num5, num7, num6, num2));
			num7 += num2 + 8f;
			DrawControls(new Rect(num5, num7, num6, 30f));
			num7 += 34f;
			DrawProgress(new Rect(num5, num7, num6, 22f));
			num7 += 26f;
			DrawFolderRow(new Rect(num5, num7, num6, 30f));
			num7 += 34f;
			DrawStatus(new Rect(num5, num7, num6, 22f));
		}

		private void DrawList(Rect area)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			if (_files.Count == 0)
			{
				GUI.Label(area, "No songs yet. Put .mid files in the songs folder, then click Refresh.", _emptyStyle);
				return;
			}
			float num = (float)_files.Count * 34f - 4f;
			float num2 = ((num > ((Rect)(ref area)).height + 0.5f) ? (((Rect)(ref area)).width - 16f - 4f) : ((Rect)(ref area)).width);
			int num3 = -1;
			_scroll = GUI.BeginScrollView(area, _scroll, new Rect(0f, 0f, num2, num), false, false);
			for (int i = 0; i < _files.Count; i++)
			{
				Rect val = new Rect(0f, (float)i * 34f, num2, 30f);
				bool flag = _performer.IsPlaying && _files[i] == _songPath;
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(_files[i]);
				if (GUI.Button(val, flag ? ("► " + fileNameWithoutExtension) : fileNameWithoutExtension, flag ? _playingStyle : _songStyle))
				{
					num3 = i;
				}
			}
			GUI.EndScrollView();
			if (num3 >= 0)
			{
				PlayFile(_files[num3]);
			}
		}

		private void DrawControls(Rect row)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			List<SongPart> list = Parts();
			string text = ((list.Count > 0) ? ("Part: " + list[Mathf.Clamp(_partIndex, 0, list.Count - 1)].Label) : "Part: none");
			GUI.enabled = list.Count > 1;
			if (GUI.Button(new Rect(((Rect)(ref row)).x, ((Rect)(ref row)).y, ((Rect)(ref row)).width - 70f - 4f, ((Rect)(ref row)).height), text, _buttonStyle))
			{
				NextPart();
			}
			GUI.enabled = _performer.IsPlaying;
			if (GUI.Button(new Rect(((Rect)(ref row)).xMax - 70f, ((Rect)(ref row)).y, 70f, ((Rect)(ref row)).height), "Stop", _buttonStyle))
			{
				_performer.Stop();
			}
			GUI.enabled = true;
		}

		private void DrawProgress(Rect row)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			if (!_performer.IsPlaying || _song == null)
			{
				GUI.Label(row, (_files.Count > 0) ? "Click a song to play it" : "", _tipStyle);
				return;
			}
			float num = Mathf.Min(_performer.PositionMs, _song.LengthMs);
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref row)).x, ((Rect)(ref row)).y + ((Rect)(ref row)).height / 2f - 3f, ((Rect)(ref row)).width - 100f - 4f, 6f);
			Color color = GUI.color;
			GUI.color = new Color(1f, 1f, 1f, 0.2f);
			GUI.DrawTexture(val, (Texture)(object)Texture2D.whiteTexture);
			GUI.color = Color32.op_Implicit(new Color32((byte)124, (byte)217, (byte)146, byte.MaxValue));
			float num2 = ((_song.LengthMs > 0f) ? (num / _song.LengthMs) : 0f);
			GUI.DrawTexture(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).y, ((Rect)(ref val)).width * num2, ((Rect)(ref val)).height), (Texture)(object)Texture2D.whiteTexture);
			GUI.color = color;
			GUI.Label(new Rect(((Rect)(ref row)).xMax - 100f, ((Rect)(ref row)).y, 100f, ((Rect)(ref row)).height), Clock(num) + " / " + Clock(_song.LengthMs), _timeStyle);
		}

		private void DrawFolderRow(Rect row)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			float num = (((Rect)(ref row)).width - 4f) / 2f;
			if (GUI.Button(new Rect(((Rect)(ref row)).x, ((Rect)(ref row)).y, num, ((Rect)(ref row)).height), "Open songs folder", _buttonStyle))
			{
				OpenFolder();
			}
			if (GUI.Button(new Rect(((Rect)(ref row)).xMax - num, ((Rect)(ref row)).y, num, ((Rect)(ref row)).height), "Refresh", _buttonStyle))
			{
				RefreshList();
				Status((_files.Count == 1) ? "Found 1 song" : ("Found " + _files.Count + " songs"));
			}
		}

		private void DrawStatus(Rect row)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (_status != null && Time.unscaledTime < _statusUntil)
			{
				GUI.Label(row, _status, _statusStyle);
			}
			else if (_performer.IsPlaying)
			{
				GUI.Label(row, "Everyone nearby hears it. Space or Esc stands up.", _tipStyle);
			}
		}

		private unsafe static string InstrumentName(InstrumentType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			if ((int)type != 2)
			{
				return ((object)(*(InstrumentType*)(&type))/*cast due to .constrained prefix*/).ToString();
			}
			return "Drums";
		}

		private static string Clock(float ms)
		{
			int num = Mathf.FloorToInt(ms / 1000f);
			return num / 60 + ":" + (num % 60).ToString("00");
		}

		private void MakeStyles()
		{
			//IL_002a: 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_0058: 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_0087: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_0110: 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_0120: Expected O, but got Unknown
			//IL_0120: 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_0133: Expected O, but got Unknown
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			Color color = default(Color);
			((Color)(ref color))..ctor(1f, 1f, 1f, 0.65f);
			_boxStyle = PanelStack.MakeStyle((TextAnchor)0);
			_titleStyle = Label(15, Color.white, (TextAnchor)3);
			_titleStyle.richText = true;
			_instrumentStyle = Label(13, color, (TextAnchor)5);
			_tipStyle = Label(14, color, (TextAnchor)3);
			_timeStyle = Label(14, color, (TextAnchor)5);
			_statusStyle = Label(14, Color32.op_Implicit(new Color32(byte.MaxValue, (byte)217, (byte)102, byte.MaxValue)), (TextAnchor)3);
			_emptyStyle = Label(14, color, (TextAnchor)3);
			_emptyStyle.wordWrap = true;
			_buttonStyle = new GUIStyle(GUI.skin.button)
			{
				fontSize = 15,
				padding = new RectOffset(6, 6, 2, 2),
				clipping = (TextClipping)1,
				richText = false
			};
			_songStyle = new GUIStyle(GUI.skin.button)
			{
				fontSize = 15,
				alignment = (TextAnchor)3,
				padding = new RectOffset(10, 6, 2, 2),
				richText = false,
				clipping = (TextClipping)1
			};
			_playingStyle = new GUIStyle(_songStyle);
			_playingStyle.normal.textColor = Color32.op_Implicit(new Color32((byte)124, (byte)217, (byte)146, byte.MaxValue));
			_playingStyle.hover.textColor = _playingStyle.normal.textColor;
		}

		private static GUIStyle Label(int size, Color color, TextAnchor alignment)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			GUIStyle val = new GUIStyle(GUI.skin.label)
			{
				fontSize = size,
				alignment = alignment,
				richText = false,
				wordWrap = false,
				clipping = (TextClipping)1,
				padding = new RectOffset(0, 0, 0, 0),
				margin = new RectOffset(0, 0, 0, 0)
			};
			val.normal.textColor = color;
			return val;
		}
	}
}