Decompiled source of SimpleGuitar v0.1.1

plugins/SimpleGuitar.dll

Decompiled 16 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SimplePiano
{
	internal static class Profile
	{
		internal const string Guid = "cn_xc.SimpleGuitar";

		internal const string Version = "0.1.1";

		internal const string Name = "Simple Guitar";

		internal const int DefaultInstr = 1;

		internal const KeyCode ToggleKey = (KeyCode)93;

		internal const string InstrName = "吉他";

		internal const bool Locked = true;
	}
	[BepInPlugin("cn_xc.SimpleGuitar", "Simple Guitar", "0.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static readonly byte NoteEventCode = 181;

		internal static readonly byte HostNoteEventCode = 186;

		private static bool _eventHooked;

		internal static bool PanelOpen;

		private static Plugin _inst;

		private static bool _drawerRegistered;

		private static int _drawerTries;

		private static float _nextDrawerTryAt;

		private static bool _drawerFailLogged;

		private static Harmony _harmony;

		private static int _callerScanTries;

		private static float _nextCallerScanAt;

		private static int _callerPatched;

		private static MethodInfo _muiRegisterDrawer;

		private static PropertyInfo _muiEditModeProp;

		private static Action<Rect> _muiDrawerCallback;

		private static Func<Rect> _muiBoundsCallback;

		private static Rect _lastKbRect;

		private static List<Song> _songs = new List<Song>();

		private static int _songIndex;

		private static bool _songPlaying;

		private static string _songPlayingName;

		private static ConfigEntry<KeyboardShortcut> _toggleKey;

		private static ConfigEntry<bool> _useVanillaRpc;

		private static ConfigEntry<bool> _localAlways;

		private static ConfigEntry<float> _volume;

		private static ConfigEntry<int> _startMidi;

		private static ConfigEntry<bool> _verbose;

		private static ConfigEntry<bool> _syncToPlayer;

		private static ConfigEntry<float> _kbX;

		private static ConfigEntry<float> _kbY;

		private static ConfigEntry<bool> _pianoInTruck;

		private static ConfigEntry<bool> _showModel;

		private static ConfigEntry<string> _instrument;

		private static ConfigEntry<float> _followDepth;

		private static GameObject _piano;

		private static MusicalValuableLogic _logic;

		private static PhotonView _pianoView;

		private static PhysGrabObject _grab;

		private static int _keyCount;

		private static int _octave;

		private static float _nextEnsureAt;

		private static bool _spawnFailLogged;

		private static bool _rpcFailLogged;

		private static bool _grabFailLogged;

		private static bool _nonHostWarned;

		private static bool _pianoPlaced;

		private static bool _nonHostLocalLogged;

		private static bool _sceneWarned;

		private static bool _vramLogged;

		private static bool _kbDragging;

		private static Vector2 _kbDragStart;

		private static Vector2 _kbDragOrigin;

		private static int _played;

		private static int _seenKeys;

		private static int _notReadyLogged;

		private static int _baseAutocorrected;

		private static MethodInfo _playKeyMethod;

		private static bool _playKeyErrLogged;

		private static AudioSource _localAudio;

		private static readonly FieldInfo _keysField = typeof(MusicalValuableLogic).GetField("musicKeys");

		private static readonly FieldInfo _countField = typeof(MusicalValuableLogic).GetField("numberOfKeys", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly string[] InstrNames = new string[4] { "钢琴", "吉他", "竖琴", "班卓" };

		private static readonly string[] InstrPaths = new string[4] { "Valuables/05 Wide/Valuable Manor Piano", "Valuables/04 Big/Valuable Arctic Guitar", "Valuables/06 Tall/Valuable Manor Harp", "Valuables/04 Big/Valuable Desert Banjo" };

		private static readonly int[] InstrKeys = new int[4] { 18, 12, 15, 8 };

		private static readonly int[] InstrOctaves = new int[4] { 6, 4, 5, 4 };

		private const int PianoBaseMidi = 48;

		private const int PianoMaxMidi = 121;

		private static readonly string WhiteRowZ = "zxcvbnm";

		private static readonly int[] WhiteSemiZ = new int[7] { 0, 2, 4, 5, 7, 9, 11 };

		private static readonly string WhiteRowA = "asdfghjkl";

		private static readonly int[] WhiteSemiA = new int[9] { 12, 14, 16, 17, 19, 21, 23, 24, 26 };

		private static readonly string WhiteRowQ = "qwertyuiop";

		private static readonly int[] WhiteSemiQ = new int[10] { 24, 26, 28, 29, 31, 33, 35, 36, 38, 40 };

		private static readonly string BlackRow = "12345678";

		private static readonly int[] BlackSemi = new int[8] { 25, 27, 30, 32, 34, 37, 39, 41 };

		private static readonly string[] NoteNames = new string[12]
		{
			"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A",
			"A#", "B"
		};

		private static bool _prevCursorVisible;

		private static CursorLockMode _prevCursorLock;

		private static bool _cursorStateSaved;

		private static ConfigEntry<string> _uiPosSaved;

		private static float _uiX = -1f;

		private static float _uiY = -1f;

		private static ConfigEntry<string> _uiOffSaved;

		private static bool _moveMode;

		private static float _nextKbLogAt;

		private static float _uiOffX;

		private static float _uiOffY;

		private static bool _uiPosLoaded;

		private static FieldInfo _cursorUnlockTimerField;

		private static float _nextWaitLogAt;

		private static bool _spawnWaitLogged;

		private static float _joinSeenAt;

		internal static int _lastLocalIdx = -1;

		internal static float _lastLocalAt = -99f;

		private static readonly Dictionary<int, Rect> _fxRects = new Dictionary<int, Rect>();

		private static Texture2D _white;

		private static readonly Dictionary<int, KeyValuePair<float, Color>> _fx = new Dictionary<int, KeyValuePair<float, Color>>();

		private static readonly int[] WhiteOffsets = new int[7] { 0, 2, 4, 5, 7, 9, 11 };

		private static readonly string[] GuitarStrings = new string[6] { "E", "A", "D", "G", "B", "e" };

		private static GUIStyle _boardStyle;

		private static GUIStyle _keyStyle;

		internal static int LastLocalIdx => _lastLocalIdx;

		internal static float LastLocalAt => _lastLocalAt;

		private static int BaseMidi
		{
			get
			{
				if (_startMidi != null)
				{
					return _startMidi.Value;
				}
				return 48;
			}
		}

		private static void MigrateOldConfig()
		{
			try
			{
				string configPath = Paths.ConfigPath;
				string text = Path.Combine(configPath, "cn_xc.SimplePiano.cfg");
				string text2 = Path.Combine(configPath, "cn_xc.PianoSimple.cfg");
				bool flag = false;
				if (!File.Exists(text) && File.Exists(text2))
				{
					File.Copy(text2, text, overwrite: false);
					flag = true;
				}
				string path = Path.Combine(configPath, "PianoSimple", "Songs");
				string text3 = Path.Combine(configPath, "SimplePiano", "Songs");
				if (Directory.Exists(path))
				{
					Directory.CreateDirectory(text3);
					string[] files = Directory.GetFiles(path);
					foreach (string text4 in files)
					{
						string text5 = Path.Combine(text3, Path.GetFileName(text4));
						if (!File.Exists(text5))
						{
							File.Copy(text4, text5, overwrite: false);
							flag = true;
						}
					}
				}
				if (flag && Log != null)
				{
					Log.LogInfo((object)"[钢琴] 已从旧版 PianoSimple 迁移配置/曲目");
				}
			}
			catch (Exception ex)
			{
				if (Log != null)
				{
					Log.LogWarning((object)("[钢琴] 迁移旧配置失败: " + ex.Message));
				}
			}
		}

		private void Awake()
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Expected O, but got Unknown
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: 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_0363: Expected O, but got Unknown
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Expected O, but got Unknown
			//IL_03a9: Expected O, but got Unknown
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Invalid comparison between Unknown and I4
			//IL_0438: 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_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0446: Invalid comparison between I4 and Unknown
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Invalid comparison between Unknown and I4
			//IL_0454: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			MigrateOldConfig();
			_inst = this;
			try
			{
				PhotonNetwork.NetworkingClient.EventReceived += OnPhotonEvent;
				_eventHooked = true;
				_joinSeenAt = Time.unscaledTime;
			}
			catch
			{
			}
			try
			{
				_songs = Songs.LoadAll();
				if (_songIndex >= _songs.Count)
				{
					_songIndex = 0;
				}
				Log.LogInfo((object)("[钢琴] 曲目目录: " + Songs.FolderPath));
				Log.LogInfo((object)("[钢琴] 已加载曲目 " + _songs.Count + " 首" + ((_songs.Count > 0) ? ("(" + _songs[0].Name + ((_songs.Count > 1) ? " …" : "") + ")") : ":把 .mid 或 .txt 放进该目录")));
			}
			catch
			{
			}
			_toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("吉他", "开关键", new KeyboardShortcut((KeyCode)93, Array.Empty<KeyCode>()), "打开/关闭钢琴面板。");
			_useVanillaRpc = ((BaseUnityPlugin)this).Config.Bind<bool>("吉他", "使用原版RPC(全员可听)", true, "调用原版钢琴 RPC,所有玩家按原版逻辑发声。");
			_localAlways = ((BaseUnityPlugin)this).Config.Bind<bool>("吉他", "同时本地播放(2D)", false, "额外在本机用 2D 音源播放一遍:听不到声音时打开,用来判断是音源问题还是 RPC 问题。");
			_volume = ((BaseUnityPlugin)this).Config.Bind<float>("吉他", "音量", 0.8f, new ConfigDescription("本地播放音量。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 1.5f), Array.Empty<object>()));
			_startMidi = ((BaseUnityPlugin)this).Config.Bind<int>("吉他", "基音MIDI_0号键", 48, new ConfigDescription("0 号键的 MIDI 音高(默认 48=C3)。整体偏高/偏低就调它,每差 12 差一个八度。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 60), Array.Empty<object>()));
			_syncToPlayer = ((BaseUnityPlugin)this).Config.Bind<bool>("吉他", "钢琴位置跟随演奏者", true, "开启后钢琴会移到演奏者身边(否则声音在生成点 -4000 米,别人听不到)。客机端会通过原版位移同步收到同样的位置。");
			_followDepth = ((BaseUnityPlugin)this).Config.Bind<float>("吉他", "跟随深度(米)", 1.2f, new ConfigDescription("钢琴放在演奏者下方多少米(藏在楼板下,减少别人看见)。", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 5f), Array.Empty<object>()));
			_uiPosSaved = ((BaseUnityPlugin)this).Config.Bind<string>("吉他界面", "面板坐标", "-1,-1", "钢琴面板左上角坐标(X,Y),-1 表示自动放在屏幕下方居中。拖动后自动保存。");
			_uiOffSaved = ((BaseUnityPlugin)this).Config.Bind<string>("吉他界面", "钢琴偏移", "0,0", "钢琴面板相对位置偏移(X,Y),F3 拖动模式里拖完自动保存。");
			_kbX = ((BaseUnityPlugin)this).Config.Bind<float>("吉他界面", "钢琴面板X", -1f, "钢琴面板左上角 X 坐标;-1 表示自动(屏幕下方居中)。不再随 MoreUIPanel 面板移动。");
			_kbY = ((BaseUnityPlugin)this).Config.Bind<float>("吉他界面", "钢琴面板Y", -1f, "钢琴面板左上角 Y 坐标;-1 表示自动。");
			_pianoInTruck = ((BaseUnityPlugin)this).Config.Bind<bool>("吉他", "固定在卡车", true, "开启后隐形钢琴固定在卡车位置(不跟着演奏者跑),适合在卡车里弹。");
			_showModel = ((BaseUnityPlugin)this).Config.Bind<bool>("吉他", "显示钢琴模型", true, "是否显示卡车里的钢琴本体(有模型但不能碰/不能搬)。显存紧张时建议关闭。");
			_instrument = ((BaseUnityPlugin)this).Config.Bind<string>("吉他", "乐器", "钢琴", "选择乐器:钢琴 / 吉他 / 竖琴 / 班卓(切换后自动重新生成)。");
			_verbose = ((BaseUnityPlugin)this).Config.Bind<bool>("吉他调试", "详细日志", false, "输出调试信息。");
			try
			{
				Harmony val = new Harmony("cn_xc.SimplePiano");
				_harmony = val;
				val.PatchAll(Assembly.GetExecutingAssembly());
				int num = PatchInputManager(val);
				Log.LogInfo((object)("[钢琴] InputManager 已拦截 " + num + " 个取值方法(面板打开时全部返回中值)"));
				Log.LogInfo((object)"[钢琴] 跳过全局 Input 拦截(只按调用方拦,避免影响面板拖动/其它 UI 模组)");
				int num2 = PatchCallersOfLegacyInput(val);
				Log.LogInfo((object)("[钢琴] 旧版 Input 调用方拦截 " + num2 + " 个方法(用于屏蔽 Fly/小地图 等模组快捷键)"));
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[钢琴] 输入拦截补丁失败: " + ex.Message));
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"[钢琴] v0.1.1 已加载");
			try
			{
				KeyboardShortcut value;
				if (_toggleKey != null)
				{
					value = _toggleKey.Value;
					if ((int)((KeyboardShortcut)(ref value)).MainKey == 112)
					{
						goto IL_0431;
					}
					value = _toggleKey.Value;
					if ((int)((KeyboardShortcut)(ref value)).MainKey == 103)
					{
						goto IL_0431;
					}
				}
				goto end_IL_03f9;
				IL_0431:
				value = _toggleKey.Value;
				if (93 != (int)((KeyboardShortcut)(ref value)).MainKey)
				{
					_toggleKey.Value = new KeyboardShortcut((KeyCode)93, Array.Empty<KeyCode>());
					try
					{
						if ((Object)(object)_inst != (Object)null)
						{
							((BaseUnityPlugin)_inst).Config.Save();
						}
					}
					catch
					{
					}
					Log.LogInfo((object)("[钢琴] 开关键已迁移为 " + ((object)(KeyCode)93/*cast due to .constrained prefix*/).ToString()));
				}
				end_IL_03f9:;
			}
			catch
			{
			}
			TryRegisterDrawer();
			LoadUiPos();
			LoadUiOff();
		}

		private static void V(string s)
		{
			if (_verbose != null && _verbose.Value && Log != null)
			{
				Log.LogDebug((object)s);
			}
		}

		private static void GetUiOrigin(float w, float h, out float x, out float y)
		{
			if (_uiX >= 0f && _uiY >= 0f)
			{
				x = _uiX;
				y = _uiY;
			}
			else
			{
				x = ((float)Screen.width - w) * 0.5f;
				y = (float)Screen.height - h - 96f;
			}
		}

		private static void LoadUiPos()
		{
			try
			{
				if (_uiPosSaved == null || _uiPosLoaded)
				{
					return;
				}
				_uiPosLoaded = true;
				string value = _uiPosSaved.Value;
				if (!string.IsNullOrEmpty(value))
				{
					string[] array = value.Split(new char[1] { ',' });
					if (array.Length == 2 && float.TryParse(array[0], out var result) && float.TryParse(array[1], out var result2))
					{
						_uiX = result;
						_uiY = result2;
					}
				}
			}
			catch
			{
			}
		}

		private static void LoadUiOff()
		{
			try
			{
				if (_uiOffSaved == null)
				{
					return;
				}
				string value = _uiOffSaved.Value;
				if (!string.IsNullOrEmpty(value))
				{
					string[] array = value.Split(new char[1] { ',' });
					if (array.Length == 2 && float.TryParse(array[0], out var result) && float.TryParse(array[1], out var result2))
					{
						_uiOffX = result;
						_uiOffY = result2;
					}
				}
			}
			catch
			{
			}
		}

		private static void SaveUiOff()
		{
			try
			{
				if (_uiOffSaved != null)
				{
					_uiOffSaved.Value = _uiOffX.ToString("F0") + "," + _uiOffY.ToString("F0");
				}
			}
			catch
			{
			}
		}

		private static void SaveUiPos()
		{
			try
			{
				if (_uiPosSaved != null)
				{
					_uiPosSaved.Value = _uiX.ToString("F0") + "," + _uiY.ToString("F0");
				}
			}
			catch
			{
			}
		}

		private static void EnterUiMode()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!_cursorStateSaved)
				{
					_prevCursorVisible = Cursor.visible;
					_prevCursorLock = Cursor.lockState;
					_cursorStateSaved = true;
				}
				UnlockCursor();
			}
			catch
			{
			}
		}

		private static void ExitUiMode()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (_cursorStateSaved)
				{
					Cursor.visible = _prevCursorVisible;
					Cursor.lockState = _prevCursorLock;
					_cursorStateSaved = false;
				}
			}
			catch
			{
			}
		}

		private static void UnlockCursor()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((int)Cursor.lockState != 0)
				{
					Cursor.lockState = (CursorLockMode)0;
				}
				if (!Cursor.visible)
				{
					Cursor.visible = true;
				}
			}
			catch
			{
			}
			try
			{
				CursorManager instance = CursorManager.instance;
				if ((Object)(object)instance != (Object)null)
				{
					if (_cursorUnlockTimerField == null)
					{
						_cursorUnlockTimerField = typeof(CursorManager).GetField("unlockTimer", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					}
					if (_cursorUnlockTimerField != null)
					{
						_cursorUnlockTimerField.SetValue(instance, -1234f);
					}
				}
			}
			catch
			{
			}
		}

		private static void DisablePlayerInput()
		{
			try
			{
				PlayerController instance = PlayerController.instance;
				if ((Object)(object)instance != (Object)null)
				{
					instance.InputDisable(0.25f);
				}
			}
			catch
			{
			}
		}

		private void Update()
		{
			try
			{
				LazyCallerRescan();
			}
			catch
			{
			}
			try
			{
				RetryDrawerRegister();
			}
			catch
			{
			}
			try
			{
				EnsureSceneOk();
			}
			catch
			{
			}
			if (PanelOpen)
			{
				DisablePlayerInput();
				UnlockCursor();
			}
			try
			{
				EnsurePiano();
			}
			catch (Exception ex)
			{
				V("Update: " + ex.Message);
			}
		}

		private static int PatchCallersOfLegacyInput(Harmony harmony)
		{
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Expected O, but got Unknown
			int num = 0;
			try
			{
				MethodInfo method = typeof(InputPrefixes).GetMethod("SkipPrefix", BindingFlags.Static | BindingFlags.Public);
				Type typeFromHandle = typeof(Input);
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				foreach (Assembly assembly in assemblies)
				{
					string name = assembly.GetName().Name;
					if ((name.IndexOf("REPOFly", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Minimap", StringComparison.OrdinalIgnoreCase) < 0) || name.StartsWith("UnityEngine") || name.StartsWith("System") || name.StartsWith("Photon") || name.StartsWith("BepInEx") || name.StartsWith("0Harmony") || name.StartsWith("MonoMod"))
					{
						continue;
					}
					Type[] types;
					try
					{
						types = assembly.GetTypes();
					}
					catch
					{
						continue;
					}
					Type[] array = types;
					foreach (Type type in array)
					{
						if (type == null || type.ContainsGenericParameters)
						{
							continue;
						}
						MethodInfo[] methods;
						try
						{
							methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
						}
						catch
						{
							continue;
						}
						MethodInfo[] array2 = methods;
						foreach (MethodInfo methodInfo in array2)
						{
							if (methodInfo == null || methodInfo.IsAbstract || methodInfo.IsGenericMethodDefinition)
							{
								continue;
							}
							MethodBody methodBody;
							try
							{
								methodBody = methodInfo.GetMethodBody();
							}
							catch
							{
								methodBody = null;
							}
							if (methodBody == null)
							{
								continue;
							}
							byte[] array3;
							try
							{
								array3 = methodBody.GetILAsByteArray();
							}
							catch
							{
								array3 = null;
							}
							if (array3 == null || array3.Length < 5)
							{
								continue;
							}
							bool flag = false;
							for (int l = 0; l + 4 < array3.Length; l++)
							{
								if (flag)
								{
									break;
								}
								byte b = array3[l];
								if (b != 40 && b != 111)
								{
									continue;
								}
								int metadataToken = BitConverter.ToInt32(array3, l + 1);
								MethodBase methodBase = null;
								try
								{
									methodBase = methodInfo.Module.ResolveMethod(metadataToken, null, null);
								}
								catch
								{
									methodBase = null;
								}
								if (!(methodBase == null) && !(methodBase.DeclaringType != typeFromHandle))
								{
									string name2 = methodBase.Name;
									switch (name2)
									{
									case "GetKey":
									case "GetKeyDown":
									case "GetKeyUp":
									case "GetMouseButton":
									case "GetMouseButtonDown":
									case "GetMouseButtonUp":
										flag = true;
										V("拦调用方: " + type.FullName + "." + methodInfo.Name + " → Input." + name2);
										break;
									}
								}
							}
							if (flag)
							{
								try
								{
									harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(method), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
									num++;
								}
								catch
								{
								}
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[钢琴] 调用方拦截异常: " + ex.Message));
			}
			return num;
		}

		private static int PatchLegacyInput(Harmony harmony)
		{
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			int num = 0;
			MethodInfo method = typeof(InputPrefixes).GetMethod("BoolPrefix", BindingFlags.Static | BindingFlags.Public);
			MethodInfo method2 = typeof(InputPrefixes).GetMethod("FloatPrefix", BindingFlags.Static | BindingFlags.Public);
			typeof(InputPrefixes).GetMethod("Vector2Prefix", BindingFlags.Static | BindingFlags.Public);
			MethodInfo method3 = typeof(InputPrefixes).GetMethod("PropertyBoolPrefix", BindingFlags.Static | BindingFlags.Public);
			MethodInfo[] methods = typeof(Input).GetMethods(BindingFlags.Static | BindingFlags.Public);
			foreach (MethodInfo methodInfo in methods)
			{
				string name = methodInfo.Name;
				if (name != "GetKey" && name != "GetKeyDown" && name != "GetKeyUp" && name != "GetMouseButton" && name != "GetMouseButtonDown" && name != "GetMouseButtonUp" && name != "GetAxis" && name != "GetAxisRaw" && name != "get_anyKey" && name != "get_anyKeyDown")
				{
					continue;
				}
				MethodInfo methodInfo2 = ((!(methodInfo.ReturnType == typeof(bool))) ? ((methodInfo.ReturnType == typeof(float)) ? method2 : null) : (name.StartsWith("get_") ? method3 : method));
				if (methodInfo2 == null)
				{
					continue;
				}
				try
				{
					harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					num++;
				}
				catch (Exception ex)
				{
					if (num < 3)
					{
						Log.LogWarning((object)("[钢琴] 旧版 Input 拦截失败 " + name + ": " + ex.GetType().Name));
					}
				}
			}
			return num;
		}

		private static int PatchInputManager(Harmony harmony)
		{
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Expected O, but got Unknown
			int num = 0;
			try
			{
				MethodInfo method = typeof(InputPrefixes).GetMethod("BoolPrefix", BindingFlags.Static | BindingFlags.Public);
				MethodInfo method2 = typeof(InputPrefixes).GetMethod("FloatPrefix", BindingFlags.Static | BindingFlags.Public);
				MethodInfo method3 = typeof(InputPrefixes).GetMethod("Vector2Prefix", BindingFlags.Static | BindingFlags.Public);
				MethodInfo[] methods = typeof(InputManager).GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo == null || methodInfo.IsAbstract || methodInfo.IsGenericMethodDefinition)
					{
						continue;
					}
					string name = methodInfo.Name;
					if ((!name.StartsWith("Key") && !name.StartsWith("Get") && name.IndexOf("Movement", StringComparison.Ordinal) < 0 && name.IndexOf("Move", StringComparison.Ordinal) < 0 && name.IndexOf("Axis", StringComparison.Ordinal) < 0) || name.IndexOf("Setup", StringComparison.Ordinal) >= 0 || name.IndexOf("Bind", StringComparison.Ordinal) >= 0)
					{
						continue;
					}
					MethodInfo methodInfo2 = ((methodInfo.ReturnType == typeof(bool)) ? method : ((methodInfo.ReturnType == typeof(float)) ? method2 : ((methodInfo.ReturnType == typeof(Vector2)) ? method3 : null)));
					if (!(methodInfo2 == null))
					{
						try
						{
							harmony.Patch((MethodBase)methodInfo, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
							num++;
						}
						catch
						{
						}
					}
				}
			}
			catch
			{
			}
			return num;
		}

		private static bool PlayViaPlayKey(int idx)
		{
			try
			{
				if (_playKeyMethod == null)
				{
					_playKeyMethod = typeof(MusicalValuableLogic).GetMethod("PlayKey", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				if (_playKeyMethod == null || (Object)(object)_logic == (Object)null)
				{
					return false;
				}
				_playKeyMethod.Invoke(_logic, new object[2] { idx, 0 });
				return true;
			}
			catch (Exception ex)
			{
				if (!_playKeyErrLogged)
				{
					_playKeyErrLogged = true;
					Log.LogWarning((object)("[钢琴] PlayKey 调用失败:" + ex.GetType().Name + " " + ex.Message));
				}
				return false;
			}
		}

		private static void MovePianoToPlayer()
		{
			//IL_00a8: 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)
			//IL_00b8: 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_0098: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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_015d: 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_0070: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: 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_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)_piano == (Object)null || (_syncToPlayer != null && !_syncToPlayer.Value))
				{
					return;
				}
				bool flag = _pianoInTruck != null && _pianoInTruck.Value;
				if (flag && _pianoPlaced)
				{
					return;
				}
				Vector3 val2;
				if (flag)
				{
					Vector3 val = Vector3.zero;
					bool flag2 = false;
					try
					{
						if ((Object)(object)TruckSafetySpawnPoint.instance != (Object)null)
						{
							val = ((Component)TruckSafetySpawnPoint.instance).transform.position;
							flag2 = true;
						}
					}
					catch
					{
					}
					if (!flag2)
					{
						PlayerAvatar instance = PlayerAvatar.instance;
						if ((Object)(object)instance != (Object)null)
						{
							val = ((Component)instance).transform.position;
							flag2 = true;
						}
					}
					if (!flag2)
					{
						return;
					}
					val2 = val + Vector3.up * 0.05f;
				}
				else
				{
					PlayerAvatar instance2 = PlayerAvatar.instance;
					if ((Object)(object)instance2 == (Object)null)
					{
						return;
					}
					float num = ((_followDepth == null) ? 1.2f : _followDepth.Value);
					val2 = ((Component)instance2).transform.position + Vector3.down * num;
				}
				Vector3 val3 = _piano.transform.position - val2;
				if (((Vector3)(ref val3)).sqrMagnitude < 0.04f)
				{
					_pianoPlaced = true;
					return;
				}
				_piano.transform.position = val2;
				if ((Object)(object)_grab != (Object)null)
				{
					_grab.midPoint = val2;
				}
				_pianoPlaced = true;
				Log.LogInfo((object)("[钢琴] 钢琴已固定在" + (flag ? "卡车" : "演奏者脚下") + " @" + ((Vector3)(ref val2)).ToString("F1")));
			}
			catch
			{
			}
		}

		private static Vector3 SpawnPos()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				PlayerAvatar instance = PlayerAvatar.instance;
				float num = ((_followDepth == null) ? 1.2f : _followDepth.Value);
				if ((Object)(object)instance != (Object)null)
				{
					return ((Component)instance).transform.position + Vector3.down * num;
				}
			}
			catch
			{
			}
			return new Vector3(0f, -4000f, 0f);
		}

		private static void RespawnPianoAtPlayer()
		{
			try
			{
				if ((Object)(object)_piano != (Object)null)
				{
					if ((Object)(object)_piano.GetComponent<PhotonView>() != (Object)null && PhotonNetwork.InRoom)
					{
						PhotonNetwork.Destroy(_piano);
					}
					else
					{
						Object.Destroy((Object)(object)_piano);
					}
					_piano = null;
					_logic = null;
					_pianoView = null;
					_grab = null;
					_keyCount = 0;
				}
				_nextEnsureAt = 0f;
				Log.LogInfo((object)"[钢琴] 已请求在当前位置重新生成钢琴");
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[钢琴] 重新生成失败: " + ex.Message));
			}
		}

		private static void LazyCallerRescan()
		{
			if (_harmony != null && _callerPatched <= 0 && _callerScanTries < 6 && !(Time.unscaledTime < _nextCallerScanAt))
			{
				_nextCallerScanAt = Time.unscaledTime + 10f;
				_callerScanTries++;
				int num = PatchCallersOfLegacyInput(_harmony);
				if (num > 0)
				{
					_callerPatched += num;
					Log.LogInfo((object)("[钢琴] 第 " + _callerScanTries + " 轮扫描:新拦截 " + num + " 个调用方(累计 " + _callerPatched + ")"));
				}
			}
		}

		private static int InstrIndex()
		{
			try
			{
				return 1;
			}
			catch
			{
			}
			return 0;
		}

		private static string InstrPath()
		{
			return InstrPaths[InstrIndex()];
		}

		private static int InstrOct()
		{
			return InstrOctaves[InstrIndex()];
		}

		private static int InstrKeyLimit()
		{
			return InstrKeys[InstrIndex()] * InstrOctaves[InstrIndex()];
		}

		private static void RefreshPiano()
		{
			try
			{
				if ((Object)(object)_piano != (Object)null)
				{
					if (PhotonNetwork.InRoom && (Object)(object)_piano.GetComponent<PhotonView>() != (Object)null && _piano.GetComponent<PhotonView>().IsMine)
					{
						PhotonNetwork.Destroy(_piano);
					}
					else
					{
						Object.Destroy((Object)(object)_piano);
					}
				}
			}
			catch
			{
			}
			_piano = null;
			_logic = null;
			_pianoView = null;
			_grab = null;
			_pianoPlaced = false;
			_fx.Clear();
		}

		private static void EnsurePiano()
		{
			//IL_0073: 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_0088: 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_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: 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)
			if (Time.unscaledTime < _nextEnsureAt)
			{
				return;
			}
			_nextEnsureAt = Time.unscaledTime + 2f;
			if ((Object)(object)_piano != (Object)null)
			{
				return;
			}
			bool inRoom = PhotonNetwork.InRoom;
			if (!PianoSceneAllowed())
			{
				LogSpawnWait("不在关卡场景(商店/卡车不生成)");
				return;
			}
			if ((Object)(object)LevelGenerator.Instance == (Object)null)
			{
				LogSpawnWait("LevelGenerator 为空");
				return;
			}
			if (!LevelGenerator.Instance.Generated)
			{
				LogSpawnWait("关卡还在生成");
				return;
			}
			try
			{
				Vector3 val = SpawnPos();
				if (inRoom && PhotonNetwork.IsMasterClient)
				{
					_piano = PhotonNetwork.Instantiate(InstrPath(), val, Quaternion.identity, (byte)0, (object[])null);
				}
				else if (inRoom)
				{
					MusicalValuableLogic[] array = Object.FindObjectsOfType<MusicalValuableLogic>();
					for (int i = 0; i < array.Length; i++)
					{
						if (!((Object)(object)array[i] == (Object)null))
						{
							PhotonView component = ((Component)array[i]).GetComponent<PhotonView>();
							if ((Object)(object)component != (Object)null && component.ViewID != 0)
							{
								_piano = ((Component)array[i]).gameObject;
								break;
							}
						}
					}
					if ((Object)(object)_piano != (Object)null)
					{
						Log.LogInfo((object)("[钢琴] 客机已找到房主的钢琴 ViewID=" + (((Object)(object)_piano.GetComponent<PhotonView>() != (Object)null) ? _piano.GetComponent<PhotonView>().ViewID : 0)));
					}
					else
					{
						if (!(Time.unscaledTime - _joinSeenAt > 6f))
						{
							return;
						}
						GameObject val2 = Resources.Load<GameObject>(InstrPath());
						if ((Object)(object)val2 != (Object)null)
						{
							_piano = Object.Instantiate<GameObject>(val2, val, Quaternion.identity);
							if ((Object)(object)_piano != (Object)null)
							{
								((Object)_piano).name = "SimplePiano_ClientGhost";
								Renderer[] componentsInChildren = _piano.GetComponentsInChildren<Renderer>(true);
								for (int j = 0; j < componentsInChildren.Length; j++)
								{
									componentsInChildren[j].enabled = false;
								}
								Log.LogInfo((object)"[钢琴] 未找到房主的钢琴,已生成本地幽灵琴(仅本地发声)");
							}
						}
					}
				}
				else
				{
					GameObject val3 = Resources.Load<GameObject>(InstrPath());
					if ((Object)(object)val3 == (Object)null)
					{
						if (!_spawnFailLogged)
						{
							_spawnFailLogged = true;
							Log.LogWarning((object)"[钢琴] 单人模式:Resources 里找不到钢琴 prefab");
						}
						return;
					}
					_piano = Object.Instantiate<GameObject>(val3, val, Quaternion.identity);
					if ((Object)(object)_piano != (Object)null)
					{
						((Object)_piano).name = "SimplePiano_LocalPiano";
					}
				}
				if ((Object)(object)_piano == (Object)null)
				{
					if (!_spawnFailLogged)
					{
						_spawnFailLogged = true;
						Log.LogWarning((object)"[钢琴] 网络生成失败(null)");
					}
					return;
				}
				_pianoPlaced = false;
				_logic = _piano.GetComponent<MusicalValuableLogic>();
				_pianoView = _piano.GetComponent<PhotonView>();
				_grab = _piano.GetComponent<PhysGrabObject>();
				if ((Object)(object)_grab == (Object)null)
				{
					_grab = _piano.GetComponentInChildren<PhysGrabObject>(true);
				}
				if ((Object)(object)_grab == (Object)null && !_grabFailLogged)
				{
					_grabFailLogged = true;
					Log.LogWarning((object)"[钢琴] 未找到 PhysGrabObject,声音定位会退化");
				}
				Collider[] componentsInChildren2 = _piano.GetComponentsInChildren<Collider>(true);
				for (int j = 0; j < componentsInChildren2.Length; j++)
				{
					componentsInChildren2[j].enabled = false;
				}
				bool flag = _showModel != null && _showModel.Value;
				try
				{
					if (!_vramLogged)
					{
						_vramLogged = true;
						Log.LogInfo((object)("[钢琴] 显卡显存=" + SystemInfo.graphicsMemorySize + "MB(显示模型=" + flag + ")"));
					}
				}
				catch
				{
				}
				if (!flag)
				{
					Renderer[] componentsInChildren = _piano.GetComponentsInChildren<Renderer>(true);
					for (int j = 0; j < componentsInChildren.Length; j++)
					{
						componentsInChildren[j].enabled = false;
					}
				}
				Rigidbody component2 = _piano.GetComponent<Rigidbody>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.isKinematic = true;
					component2.detectCollisions = false;
				}
				PhysGrabObject[] componentsInChildren3 = _piano.GetComponentsInChildren<PhysGrabObject>(true);
				for (int j = 0; j < componentsInChildren3.Length; j++)
				{
					((Behaviour)componentsInChildren3[j]).enabled = false;
				}
				PhysGrabObjectGrabArea[] componentsInChildren4 = _piano.GetComponentsInChildren<PhysGrabObjectGrabArea>(true);
				for (int j = 0; j < componentsInChildren4.Length; j++)
				{
					((Behaviour)componentsInChildren4[j]).enabled = false;
				}
				if ((Object)(object)_pianoView != (Object)null)
				{
					_pianoView.Synchronization = (ViewSynchronization)2;
					_pianoView.ObservedComponents = null;
				}
				_keyCount = GetKeyCount();
				int num = 0;
				try
				{
					num = ((!((Object)(object)_logic == (Object)null)) ? _logic.numberOfOctaves : 0);
				}
				catch
				{
				}
				Log.LogInfo((object)("[钢琴] 隐形钢琴已生成 模式=" + ((!PhotonNetwork.InRoom) ? "单人" : (PhotonNetwork.IsMasterClient ? "多人-房主" : "多人-客机")) + " ViewID=" + (((Object)(object)_pianoView == (Object)null) ? (-1) : _pianoView.ViewID) + " 键数=" + _keyCount + " (numberOfKeys=" + CountFieldValue() + ") 八度数=" + num + " 起始MIDI=" + BaseMidi + " 首键=" + FirstKeyInfo()));
			}
			catch (Exception ex)
			{
				if (!_spawnFailLogged)
				{
					_spawnFailLogged = true;
					Log.LogWarning((object)("[钢琴] 生成异常: " + ex.GetType().Name + " " + ex.Message));
				}
			}
		}

		private void OnDestroy()
		{
			try
			{
				if (_eventHooked)
				{
					PhotonNetwork.NetworkingClient.EventReceived -= OnPhotonEvent;
				}
			}
			catch
			{
			}
			_eventHooked = false;
		}

		private static bool PianoSceneAllowed()
		{
			try
			{
				if (!SemiFunc.RunIsLevel())
				{
					return false;
				}
				RunManager instance = RunManager.instance;
				string text = (((Object)(object)instance != (Object)null && (Object)(object)instance.levelCurrent != (Object)null) ? ((Object)instance.levelCurrent).name : null);
				if (!string.IsNullOrEmpty(text) && text.IndexOf("Shop", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return false;
				}
				return true;
			}
			catch
			{
				return false;
			}
		}

		private static bool DragKeyboardInEditMode(Event e)
		{
			//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_0031: 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: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Invalid comparison between Unknown and I4
			//IL_00bc: 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)
			//IL_00cb: 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)
			//IL_0108: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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)
			try
			{
				if (!PanelEditMode() || !PanelOpen)
				{
					return false;
				}
				Rect lastKbRect = _lastKbRect;
				if (((Rect)(ref lastKbRect)).width <= 1f)
				{
					return false;
				}
				if ((int)e.type == 0 && e.button == 0 && ((Rect)(ref lastKbRect)).Contains(e.mousePosition))
				{
					_kbDragging = true;
					_kbDragStart = e.mousePosition;
					_kbDragOrigin = new Vector2((_kbX != null) ? _kbX.Value : ((Rect)(ref lastKbRect)).x, (_kbY != null) ? _kbY.Value : ((Rect)(ref lastKbRect)).y);
					return true;
				}
				if (_kbDragging && (int)e.type == 3)
				{
					Vector2 val = e.mousePosition - _kbDragStart;
					float value = Mathf.Clamp(_kbDragOrigin.x + val.x, 0f, Mathf.Max(0f, (float)Screen.width - 200f));
					float value2 = Mathf.Clamp(_kbDragOrigin.y + val.y, 0f, Mathf.Max(0f, (float)Screen.height - 120f));
					if (_kbX != null)
					{
						_kbX.Value = value;
					}
					if (_kbY != null)
					{
						_kbY.Value = value2;
					}
					return true;
				}
				if (_kbDragging && (int)e.type == 1)
				{
					_kbDragging = false;
					try
					{
						if ((Object)(object)_inst != (Object)null)
						{
							((BaseUnityPlugin)_inst).Config.Save();
						}
					}
					catch
					{
					}
					Log.LogInfo((object)("[钢琴] 键盘位置已保存: " + ((_kbX != null) ? _kbX.Value.ToString("F0") : "?") + "," + ((_kbY != null) ? _kbY.Value.ToString("F0") : "?")));
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		private static void EnsureSceneOk()
		{
			if (PanelOpen && !PianoSceneAllowed())
			{
				PanelOpen = false;
				ExitUiMode();
				_songPlaying = false;
				_fx.Clear();
				Log.LogInfo((object)"[钢琴] 已离开关卡场景,面板自动关闭");
			}
		}

		private static void LogSpawnWait(string reason)
		{
			if (!_spawnWaitLogged)
			{
				_spawnWaitLogged = true;
				if (!(Time.unscaledTime < _nextWaitLogAt))
				{
					_nextWaitLogAt = Time.unscaledTime + 10f;
					Log.LogInfo((object)("[钢琴] 等待生成隐形钢琴:" + reason));
				}
			}
		}

		private static int GetKeyCount()
		{
			if ((Object)(object)_logic == (Object)null)
			{
				return 0;
			}
			try
			{
				IList list = ((_keysField == null) ? null : (_keysField.GetValue(_logic) as IList));
				if (list != null && list.Count > 0)
				{
					return list.Count;
				}
				if (_countField != null)
				{
					return Convert.ToInt32(_countField.GetValue(_logic));
				}
				return 0;
			}
			catch
			{
				return 0;
			}
		}

		private static int CountFieldValue()
		{
			try
			{
				return (_countField == null) ? (-1) : Convert.ToInt32(_countField.GetValue(_logic));
			}
			catch
			{
				return -1;
			}
		}

		private static string FirstKeyInfo()
		{
			try
			{
				IList list = ((_keysField == null) ? null : (_keysField.GetValue(_logic) as IList));
				if (list == null || list.Count == 0)
				{
					return "(无键)";
				}
				object? obj = list[0];
				Sound val = (Sound)((obj is Sound) ? obj : null);
				if (val == null)
				{
					return "(空 Sound)";
				}
				if (val.Sounds != null && val.Sounds.Length != 0 && (Object)(object)val.Sounds[0] != (Object)null)
				{
					return ((Object)val.Sounds[0]).name + " x" + val.Sounds.Length;
				}
				if ((Object)(object)val.Source != (Object)null && (Object)(object)val.Source.clip != (Object)null)
				{
					return ((Object)val.Source.clip).name;
				}
				return "(无 clip)";
			}
			catch
			{
				return "(异常)";
			}
		}

		private static void RetryDrawerRegister()
		{
			if (!_drawerRegistered && _drawerTries < 15 && !(Time.unscaledTime < _nextDrawerTryAt))
			{
				_nextDrawerTryAt = Time.unscaledTime + 2f;
				_drawerTries++;
				TryRegisterDrawer();
				if (_drawerRegistered)
				{
					Log.LogInfo((object)("[钢琴] 第 " + _drawerTries + " 次尝试注册成功"));
				}
				else if (_drawerTries >= 15 && !_drawerFailLogged)
				{
					_drawerFailLogged = true;
					Log.LogWarning((object)"[钢琴] 注册 MoreUIPanel 绘制失败(已试 15 次),键盘将自绘、无法随面板拖动");
				}
			}
		}

		private static bool PanelEditMode()
		{
			try
			{
				if (_muiEditModeProp == null)
				{
					Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
					for (int i = 0; i < assemblies.Length; i++)
					{
						Type type = assemblies[i].GetType("MoreUIPanel.Plugin", throwOnError: false);
						if (!(type == null))
						{
							_muiEditModeProp = type.GetProperty("EditMode", BindingFlags.Static | BindingFlags.Public);
							if (_muiEditModeProp != null)
							{
								break;
							}
						}
					}
				}
				if (_muiEditModeProp == null)
				{
					return false;
				}
				return (bool)_muiEditModeProp.GetValue(null, null);
			}
			catch
			{
				return false;
			}
		}

		private static void TryRegisterDrawer()
		{
			try
			{
				Type type = null;
				Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
				for (int i = 0; i < assemblies.Length; i++)
				{
					type = assemblies[i].GetType("MoreUIPanel.Plugin", throwOnError: false);
					if (type != null)
					{
						break;
					}
				}
				if (type == null)
				{
					V("还没找到 MoreUIPanel.Plugin 类型");
					return;
				}
				MethodInfo method = type.GetMethod("RegisterDrawer", new Type[3]
				{
					typeof(string),
					typeof(Action<Rect>),
					typeof(Func<Rect>)
				});
				_muiDrawerCallback = PanelDrawer;
				_muiBoundsCallback = () => _lastKbRect;
				bool flag = false;
				if (method != null)
				{
					method.Invoke(null, new object[3] { "cn_xc.SimpleGuitar", _muiDrawerCallback, _muiBoundsCallback });
					_muiRegisterDrawer = method;
					flag = true;
				}
				else
				{
					MethodInfo method2 = type.GetMethod("RegisterDrawer", new Type[2]
					{
						typeof(string),
						typeof(Action<Rect>)
					});
					if (method2 == null)
					{
						return;
					}
					method2.Invoke(null, new object[2] { "cn_xc.SimpleGuitar", _muiDrawerCallback });
					_muiRegisterDrawer = method2;
				}
				_drawerRegistered = true;
				Log.LogInfo((object)("[钢琴] 已注册到 MoreUIPanel:重载=" + (flag ? "3参数(带可拖范围)" : "2参数(无范围!)") + "  当前范围=" + ((object)Unsafe.As<Rect, Rect>(ref _lastKbRect)/*cast due to .constrained prefix*/).ToString()));
			}
			catch (Exception ex)
			{
				if (!_drawerFailLogged)
				{
					_drawerFailLogged = true;
					Log.LogWarning((object)("[钢琴] 注册面板绘制异常: " + ex.GetType().Name + " " + ex.Message));
				}
			}
		}

		private static void PanelDrawer(Rect area)
		{
			//IL_00e5: 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)
			try
			{
				float num = Mathf.Max(600f, Mathf.Min((float)Screen.width * 0.94f, 900f));
				float num2 = 150f;
				float num3 = ((_kbX != null && _kbX.Value >= 0f) ? _kbX.Value : (((float)Screen.width - num) * 0.5f));
				float num4 = ((_kbY != null && _kbY.Value >= 0f) ? _kbY.Value : ((float)Screen.height - num2 - 150f));
				num3 = Mathf.Clamp(num3, 0f, Mathf.Max(0f, (float)Screen.width - num));
				num4 = Mathf.Clamp(num4, 0f, Mathf.Max(0f, (float)Screen.height - num2));
				_lastKbRect = new Rect(num3 - 10f, num4 - 84f, num + 20f, num2 + 128f);
				if (PanelOpen)
				{
					DrawKeyboard(num3, num4, num, num2);
				}
			}
			catch
			{
			}
		}

		private static void OnPhotonEvent(EventData e)
		{
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			try
			{
				if (e == null)
				{
					return;
				}
				if (e.Code == HostNoteEventCode)
				{
					if (e.CustomData is byte[] array && array.Length >= 1)
					{
						int num = array[0];
						if (PlayViaPlayKey(num))
						{
							_lastLocalIdx = num;
							_lastLocalAt = Time.unscaledTime;
						}
						if (_localAlways != null && _localAlways.Value)
						{
							PlayLocal(num);
						}
					}
				}
				else if (e.Code == NoteEventCode && PhotonNetwork.IsMasterClient && !((Object)(object)_pianoView == (Object)null) && _pianoView.ViewID != 0 && e.CustomData is byte[] array2 && array2.Length >= 1)
				{
					int num2 = array2[0];
					if ((Object)(object)_grab != (Object)null)
					{
						_grab.midPoint = _piano.transform.position;
					}
					_pianoView.RPC("MusicKeyPressedRPC", (RpcTarget)1, new object[2] { num2, 0 });
					try
					{
						PhotonNetwork.RaiseEvent(HostNoteEventCode, (object)new byte[1] { (byte)num2 }, new RaiseEventOptions
						{
							Receivers = (ReceiverGroup)0
						}, SendOptions.SendReliable);
						return;
					}
					catch
					{
						return;
					}
				}
			}
			catch
			{
			}
		}

		private static void SendNoteToHost(int idx)
		{
			//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_0017: 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_0026: Expected O, but got Unknown
			try
			{
				PhotonNetwork.RaiseEvent(NoteEventCode, (object)new byte[1] { (byte)idx }, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)2
				}, SendOptions.SendReliable);
			}
			catch
			{
			}
		}

		private void OnGUI()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Invalid comparison between Unknown and I4
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Invalid comparison between Unknown and I4
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Invalid comparison between Unknown and I4
			//IL_0094: 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_00a3: 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_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Invalid comparison between Unknown and I4
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Invalid comparison between Unknown and I4
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Invalid comparison between Unknown and I4
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Invalid comparison between Unknown and I4
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Invalid comparison between Unknown and I4
			//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)
			try
			{
				Event current = Event.current;
				if (current == null)
				{
					return;
				}
				if ((int)current.type == 4)
				{
					if ((int)current.keyCode == 290)
					{
						if ((Object)(object)_inst != (Object)null)
						{
							((MonoBehaviour)_inst).StartCoroutine(TestScale());
						}
						current.Use();
						return;
					}
					if ((int)current.keyCode == 288)
					{
						RespawnPianoAtPlayer();
						current.Use();
						return;
					}
					if ((int)current.keyCode == 291)
					{
						MeasureRange();
						current.Use();
						return;
					}
					if (_toggleKey != null)
					{
						KeyCode keyCode = current.keyCode;
						KeyboardShortcut value = _toggleKey.Value;
						if (keyCode == ((KeyboardShortcut)(ref value)).MainKey)
						{
							if (!PanelOpen && !PianoSceneAllowed())
							{
								if (!_sceneWarned)
								{
									_sceneWarned = true;
									Log.LogInfo((object)"[钢琴] 只能在关卡里打开钢琴(商店/卡车不可用)");
								}
								current.Use();
								return;
							}
							_sceneWarned = false;
							PanelOpen = !PanelOpen;
							if (PanelOpen)
							{
								EnterUiMode();
							}
							else
							{
								ExitUiMode();
							}
							Log.LogInfo((object)("[钢琴] 面板 " + (PanelOpen ? "打开" : "关闭")));
							current.Use();
							return;
						}
					}
					if (PanelOpen)
					{
						if ((int)current.keyCode == 287)
						{
							_songs = Songs.LoadAll();
							_songIndex = 0;
							if (_songs.Count == 0)
							{
								_songPlaying = false;
							}
							Log.LogInfo((object)("[钢琴] 重新扫描曲目: " + _songs.Count + " 首"));
							current.Use();
							return;
						}
						if ((int)current.keyCode == 59)
						{
							if (_songs.Count > 0)
							{
								_songPlaying = false;
								_songIndex = (_songIndex - 1 + _songs.Count) % _songs.Count;
								Log.LogInfo((object)("[钢琴] 选曲: " + _songs[_songIndex].Name));
							}
							current.Use();
							return;
						}
						if ((int)current.keyCode == 39)
						{
							if (_songs.Count > 0)
							{
								_songPlaying = false;
								_songIndex = (_songIndex + 1) % _songs.Count;
								Log.LogInfo((object)("[钢琴] 选曲: " + _songs[_songIndex].Name));
							}
							current.Use();
							return;
						}
						if ((int)current.keyCode == 13 || (int)current.keyCode == 271)
						{
							if (_songPlaying)
							{
								_songPlaying = false;
								Log.LogInfo((object)"[钢琴] 已停止演奏");
							}
							else if (_songs.Count > 0 && (Object)(object)_inst != (Object)null)
							{
								((MonoBehaviour)_inst).StartCoroutine(PlaySong(_songs[_songIndex]));
							}
							current.Use();
							return;
						}
						if (_seenKeys < 30)
						{
							_seenKeys++;
							Log.LogInfo((object)("[钢琴] 收到按键 keyCode=" + ((object)current.keyCode/*cast due to .constrained prefix*/).ToString() + " 字符=" + ((current.character == '\0') ? "(无)" : current.character.ToString())));
						}
						if (HandlePlayKey(current))
						{
							current.Use();
						}
						current.Use();
						return;
					}
				}
				if (PanelOpen && !_drawerRegistered)
				{
					DrawPanel();
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[钢琴] OnGUI 异常: " + ex.Message));
			}
		}

		private static Texture2D WhiteTex()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_white == (Object)null)
			{
				_white = new Texture2D(1, 1, (TextureFormat)4, false);
				_white.SetPixel(0, 0, Color.white);
				_white.Apply();
			}
			return _white;
		}

		private static void FxHit(int midi)
		{
			//IL_000f: 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_0020: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Color value = Color.HSVToRGB(Random.value, 0.9f, 1f);
				_fx[midi] = new KeyValuePair<float, Color>(Time.unscaledTime, value);
			}
			catch
			{
			}
		}

		private static void DrawPanel()
		{
			float w = Mathf.Min((float)Screen.width * 0.94f, 900f);
			float h = 150f;
			GetUiOrigin(w, h, out var x, out var y);
			DrawKeyboard(x, y, w, h);
		}

		private static void DrawKeyboard(float x, float y, float w, float h)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: 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_00fa: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: 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_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_056c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_0582: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_070c: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0677: Unknown result type (might be due to invalid IL or missing references)
			//IL_0681: Unknown result type (might be due to invalid IL or missing references)
			//IL_068d: Unknown result type (might be due to invalid IL or missing references)
			//IL_06be: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ad: Unknown result type (might be due to invalid IL or missing references)
			int num = 28;
			GUI.Box(new Rect(x - 10f, y - 84f, w + 20f, h + 128f), "");
			GUI.Label(new Rect(x, y - 80f, w, 20f), InstrTitleText());
			GUI.Label(new Rect(x, y - 60f, w, 20f), InstrHintText());
			DrawInstrumentTheme(x, y, w, h, y + 26f);
			float num2 = y - 16f;
			if (GUI.Button(new Rect(x, num2, 34f, 22f), "↻"))
			{
				_songs = Songs.LoadAll();
				_songIndex = 0;
				if (_songs.Count == 0)
				{
					_songPlaying = false;
				}
				Log.LogInfo((object)("[钢琴] 重扫曲目: " + _songs.Count));
			}
			if (GUI.Button(new Rect(x + 38f, num2, 30f, 22f), "◀") && _songs.Count > 0)
			{
				_songPlaying = false;
				_songIndex = (_songIndex - 1 + _songs.Count) % _songs.Count;
			}
			if (_songPlaying)
			{
				if (GUI.Button(new Rect(x + 72f, num2, 44f, 22f), "■"))
				{
					_songPlaying = false;
					Log.LogInfo((object)"[钢琴] 停止演奏");
				}
			}
			else if (GUI.Button(new Rect(x + 72f, num2, 44f, 22f), "▶") && !_songPlaying && _songs.Count > 0 && (Object)(object)_inst != (Object)null)
			{
				((MonoBehaviour)_inst).StartCoroutine(PlaySong(_songs[_songIndex]));
			}
			if (GUI.Button(new Rect(x + 120f, num2, 30f, 22f), "▶|") && _songs.Count > 0)
			{
				_songPlaying = false;
				_songIndex = (_songIndex + 1) % _songs.Count;
			}
			float num3 = x + 156f;
			int num4 = 0;
			int num5 = ((_songs.Count > 0) ? (_songIndex / 4) : 0);
			int num6 = num5 * 4;
			int num7 = Mathf.Min(num6 + 4, _songs.Count);
			for (int i = num6; i < num7; i++)
			{
				float num8 = Mathf.Min(180f, 150f);
				if (i == _songIndex)
				{
					GUI.color = new Color(0.5f, 1f, 0.6f);
				}
				if (GUI.Button(new Rect(num3, num2, num8, 22f), _songs[i].Name))
				{
					_songPlaying = false;
					_songIndex = i;
					Log.LogInfo((object)("[钢琴] 选曲: " + _songs[i].Name));
				}
				GUI.color = Color.white;
				num3 += num8 + 4f;
				num4++;
			}
			if (_songs.Count == 0)
			{
				GUI.Label(new Rect(x + 156f, num2, w - 160f, 22f), "(Songs 目录为空:放 .mid/.txt 后按 ↻)");
			}
			else if (_songs.Count > 4 && _songIndex >= _songs.Count)
			{
				_songIndex = 0;
			}
			string text = ((_songs.Count == 0 || _songIndex < 0 || _songIndex >= _songs.Count) ? "曲目: 无(放进 Songs 目录后按 ↻)" : ("当前曲目 " + (_songIndex + 1) + "/" + _songs.Count + ": " + _songs[_songIndex].Name + "  | 第 " + (num5 + 1) + "/" + Mathf.CeilToInt((float)_songs.Count / 4f) + " 页" + (_songPlaying ? "  ▶ 播放中" : "  (点名字或 ; ' 切换,Enter 播放)")));
			GUI.Label(new Rect(x, y - 40f, w, 20f), text);
			_fxRects.Clear();
			float num9 = w / (float)num;
			float unscaledTime = Time.unscaledTime;
			int num10 = 48 + _octave * 12;
			float num11 = y + 26f;
			if (InstrIndex() == 1)
			{
				DrawGuitarBoard(x, num11, w, h);
				DrawFxPass(Time.unscaledTime);
				GUI.color = Color.white;
				return;
			}
			if (InstrIndex() == 2)
			{
				DrawHarpBoard(x, num11, w, h);
				DrawFxPass(Time.unscaledTime);
				GUI.color = Color.white;
				return;
			}
			Rect val = default(Rect);
			for (int j = 0; j < 4; j++)
			{
				for (int k = 0; k < 7; k++)
				{
					int midi = num10 + j * 12 + WhiteOffsets[k];
					int num12 = j * 7 + k;
					((Rect)(ref val))..ctor(x + (float)num12 * num9 + 1f, num11, num9 - 2f, h);
					GUI.color = new Color(0.97f, 0.97f, 0.93f);
					GUI.DrawTexture(val, (Texture)(object)WhiteTex());
					GUI.color = Color.white;
					GUI.Label(new Rect(((Rect)(ref val)).x, ((Rect)(ref val)).yMax - 34f, ((Rect)(ref val)).width, 32f), NoteName(midi) + "\n" + KeyLabel(midi), KeyStyle());
					DrawFx(val, midi, unscaledTime);
				}
			}
			int[] array = new int[5] { 1, 3, 6, 8, 10 };
			Rect val2 = default(Rect);
			for (int l = 0; l < 4; l++)
			{
				foreach (int num13 in array)
				{
					int midi2 = num10 + l * 12 + num13;
					float num14 = x + (float)(l * 7 + WhiteIndexForOffset(num13)) * num9;
					((Rect)(ref val2))..ctor(num14 - num9 * 0.34f, num11, num9 * 0.68f, h * 0.62f);
					GUI.color = new Color(0.12f, 0.12f, 0.14f);
					GUI.DrawTexture(val2, (Texture)(object)WhiteTex());
					GUI.color = Color.white;
					GUIStyle val3 = KeyStyle();
					GUI.Label(new Rect(((Rect)(ref val2)).x, ((Rect)(ref val2)).yMax - 30f, ((Rect)(ref val2)).width, 28f), NoteName(midi2) + "\n" + KeyLabel(midi2), val3);
					DrawFx(val2, midi2, unscaledTime);
				}
			}
			GUI.color = Color.white;
			if (_fx.Count > 0)
			{
				List<KeyValuePair<int, KeyValuePair<float, Color>>> list = new List<KeyValuePair<int, KeyValuePair<float, Color>>>(_fx);
				for (int n = 0; n < list.Count; n++)
				{
					int key = list[n].Key;
					if (!_fxRects.TryGetValue(key, out var value))
					{
						bool flag = false;
						for (int num15 = 1; num15 <= 6; num15++)
						{
							if (flag)
							{
								break;
							}
							if (_fxRects.TryGetValue(key + 12 * num15, out value))
							{
								flag = true;
							}
							else if (_fxRects.TryGetValue(key - 12 * num15, out value))
							{
								flag = true;
							}
						}
						if (!flag)
						{
							continue;
						}
					}
					DrawFx(value, key, unscaledTime);
				}
			}
			GUI.color = Color.white;
		}

		private static void DrawFxPass(float now)
		{
			//IL_000c: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (_fx.Count == 0)
				{
					GUI.color = Color.white;
					return;
				}
				List<KeyValuePair<int, KeyValuePair<float, Color>>> list = new List<KeyValuePair<int, KeyValuePair<float, Color>>>(_fx);
				for (int i = 0; i < list.Count; i++)
				{
					int key = list[i].Key;
					if (!_fxRects.TryGetValue(key, out var value))
					{
						bool flag = false;
						for (int j = 1; j <= 6; j++)
						{
							if (flag)
							{
								break;
							}
							if (_fxRects.TryGetValue(key + 12 * j, out value))
							{
								flag = true;
							}
							else if (_fxRects.TryGetValue(key - 12 * j, out value))
							{
								flag = true;
							}
						}
						if (!flag)
						{
							continue;
						}
					}
					DrawFx(value, key, now);
				}
			}
			catch
			{
			}
			GUI.color = Color.white;
		}

		private static List<KeyValuePair<int, string>> WindowKeys()
		{
			List<KeyValuePair<int, string>> list = new List<KeyValuePair<int, string>>();
			int num = 48 + _octave * 12;
			for (int i = 0; i < 48; i++)
			{
				int num2 = num + i;
				string value = KeyLabel(num2);
				if (!string.IsNullOrEmpty(value))
				{
					list.Add(new KeyValuePair<int, string>(num2, value));
				}
			}
			return list;
		}

		private static GUIStyle BoardStyle()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (_boardStyle == null)
			{
				_boardStyle = new GUIStyle(GUI.skin.label);
				_boardStyle.fontSize = 12;
				_boardStyle.alignment = (TextAnchor)4;
				_boardStyle.normal.textColor = new Color(1f, 0.97f, 0.88f);
			}
			return _boardStyle;
		}

		private static void DrawGuitarBoard(float x, float y, float w, float h)
		{
			//IL_0059: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: 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_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_0261: 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_02b0: Unknown result type (might be due to invalid IL or missing references)
			List<KeyValuePair<int, string>> list = WindowKeys();
			if (list.Count == 0)
			{
				GUI.Label(new Rect(x, y, w, 24f), "吉他就绪中…");
				return;
			}
			int num = 6;
			int num2 = 8;
			int num3 = Mathf.Min(list.Count, num * num2);
			float num4 = w / (float)num2;
			float num5 = h / (float)num;
			GUI.color = new Color(0.32f, 0.2f, 0.1f, 0.55f);
			GUI.DrawTexture(new Rect(x, y, w, h), (Texture)(object)WhiteTex());
			GUI.color = new Color(0.96f, 0.93f, 0.85f, 0.9f);
			GUI.DrawTexture(new Rect(x - 5f, y, 5f, h), (Texture)(object)WhiteTex());
			GUI.color = new Color(0.85f, 0.8f, 0.7f, 0.25f);
			for (int i = 1; i <= num2; i++)
			{
				GUI.DrawTexture(new Rect(x + num4 * (float)i, y, 1f, h), (Texture)(object)WhiteTex());
			}
			for (int j = 0; j < num; j++)
			{
				GUI.color = new Color(0.93f, 0.86f, 0.72f, 0.75f);
				GUI.DrawTexture(new Rect(x, y + num5 * (float)j + num5 * 0.5f - 1f, w, (j == 0 || j == num - 1) ? 2.6f : 1.4f), (Texture)(object)WhiteTex());
			}
			Rect val = default(Rect);
			for (int k = 0; k < num3; k++)
			{
				int num6 = k % num;
				int num7 = k / num;
				((Rect)(ref val))..ctor(x + num4 * (float)num7 + 1f, y + num5 * (float)num6 + 1f, num4 - 2f, num5 - 2f);
				GUI.color = new Color(1f, 0.9f, 0.6f, 0.3f);
				GUI.DrawTexture(val, (Texture)(object)WhiteTex());
				GUI.color = Color.white;
				GUI.Label(val, list[k].Value + "\n" + NoteName(list[k].Key), BoardStyle());
				_fxRects[list[k].Key] = val;
			}
			for (int l = 0; l < num; l++)
			{
				GUI.color = new Color(1f, 0.95f, 0.8f);
				GUI.Label(new Rect(x - 22f, y + num5 * (float)l + num5 * 0.5f - 9f, 20f, 18f), GuitarStrings[l]);
			}
			GUI.color = Color.white;
		}

		private static void DrawHarpBoard(float x, float y, float w, float h)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_00a2: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: 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_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			List<KeyValuePair<int, string>> list = WindowKeys();
			if (list.Count == 0)
			{
				GUI.Label(new Rect(x, y, w, 24f), "竖琴就绪中…");
				return;
			}
			int num = Mathf.Min(list.Count, 24);
			float num2 = w / (float)num;
			GUI.color = new Color(0.3f, 0.24f, 0.08f, 0.55f);
			GUI.DrawTexture(new Rect(x, y, w, h), (Texture)(object)WhiteTex());
			GUI.color = new Color(0.95f, 0.85f, 0.55f, 0.95f);
			GUI.DrawTexture(new Rect(x - 6f, y - 6f, w + 12f, 6f), (Texture)(object)WhiteTex());
			GUI.DrawTexture(new Rect(x - 6f, y + h, w + 12f, 6f), (Texture)(object)WhiteTex());
			GUI.DrawTexture(new Rect(x - 6f, y - 6f, 6f, h + 12f), (Texture)(object)WhiteTex());
			GUI.DrawTexture(new Rect(x + w, y - 6f, 6f, h + 12f), (Texture)(object)WhiteTex());
			Rect value = default(Rect);
			for (int i = 0; i < num; i++)
			{
				((Rect)(ref value))..ctor(x + num2 * (float)i, y, num2, h);
				bool flag = NoteName(list[i].Key).StartsWith("C");
				GUI.color = (flag ? new Color(1f, 0.96f, 0.75f, 0.95f) : new Color(1f, 0.93f, 0.7f, 0.55f));
				GUI.DrawTexture(new Rect(((Rect)(ref value)).x + num2 * 0.5f - 1f, ((Rect)(ref value)).y, flag ? 2.6f : 1.3f, ((Rect)(ref value)).height), (Texture)(object)WhiteTex());
				GUI.color = Color.white;
				GUI.Label(new Rect(((Rect)(ref value)).x, ((Rect)(ref value)).yMax - 30f, num2, 28f), NoteName(list[i].Key) + "\n" + list[i].Value, KeyStyle());
				_fxRects[list[i].Key] = value;
			}
			GUI.color = Color.white;
		}

		private static string InstrTitleText()
		{
			try
			{
				int num = InstrIndex();
				int num2 = 48 + _octave * 12;
				int midi = num2 + InstrOct() * 12 - 1;
				return InstrNames[num] + "\u3000音域 " + NoteName(num2) + "~" + NoteName(midi) + "\u3000键位 " + InstrKeys[num] + "×" + InstrOctaves[num] + "=" + InstrKeyLimit() + "\u3000" + ToggleName() + " 关闭";
			}
			catch
			{
				return InstrNames[InstrIndex()];
			}
		}

		private static string InstrHintText()
		{
			return "白键 Z-M | A-L | Q-P\u3000黑键 1~8\u3000, . 换八度(当前 " + _octave + ")\u3000; ' 选曲\u3000Enter 播放\u3000F6 重扫\u3000F7 召唤\u3000F2 拖动";
		}

		private static string ToggleName()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				return "]";
			}
			catch
			{
			}
			return ((object)(KeyCode)93/*cast due to .constrained prefix*/).ToString();
		}

		private static string KeyHintText()
		{
			return "Z X C V B N M | A S D F G H J K L | Q W E R T Y U I O P";
		}

		private static void DrawInstrumentTheme(float x, float y, float w, float h, float keyTop)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				int num = InstrIndex();
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(x - 10f, y - 84f, w + 20f, h + 128f);
				switch (num)
				{
				case 1:
				{
					GUI.color = new Color(0.28f, 0.17f, 0.09f, 0.35f);
					GUI.DrawTexture(val, (Texture)(object)WhiteTex());
					GUI.color = new Color(0.93f, 0.86f, 0.72f, 0.55f);
					for (int j = 0; j < 6; j++)
					{
						float num3 = keyTop + (h - 40f) * ((float)j / 5f) + 18f;
						GUI.DrawTexture(new Rect(x, num3, w, (j == 0 || j == 5) ? 2.2f : 1.4f), (Texture)(object)WhiteTex());
					}
					break;
				}
				case 2:
				{
					GUI.color = new Color(0.35f, 0.28f, 0.08f, 0.3f);
					GUI.DrawTexture(val, (Texture)(object)WhiteTex());
					GUI.color = new Color(1f, 0.93f, 0.7f, 0.45f);
					int num2 = 15;
					for (int i = 0; i < num2; i++)
					{
						GUI.DrawTexture(new Rect(x + (w - 20f) * ((float)i / (float)(num2 - 1)) + 10f, keyTop, (i % 5 == 0) ? 2f : 1.2f, h), (Texture)(object)WhiteTex());
					}
					break;
				}
				}
				GUI.color = Color.white;
			}
			catch
			{
			}
		}

		private static int WhiteIndexForOffset(int off)
		{
			return off switch
			{
				1 => 0, 
				3 => 1, 
				6 => 3, 
				8 => 4, 
				_ => 5, 
			};
		}

		private static GUIStyle KeyStyle()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			if (_keyStyle == null)
			{
				_keyStyle = new GUIStyle(GUI.skin.label);
				_keyStyle.fontSize = 11;
				_keyStyle.alignment = (TextAnchor)7;
				_keyStyle.normal.textColor = Color.black;
			}
			return _keyStyle;
		}

		private static void DrawFx(Rect r, int midi, float now)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_005b: 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_007a: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: 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)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			if (!_fx.TryGetValue(midi, out var value))
			{
				return;
			}
			float num = now - value.Key;
			if (num > 0.9f)
			{
				try
				{
					_fx.Remove(midi);
					return;
				}
				catch
				{
					return;
				}
			}
			if (!(num < 0f) && !(num > 0.6f))
			{
				Color value2 = value.Value;
				if (num < 0.18f)
				{
					GUI.color = new Color(value2.r, value2.g, value2.b, 0.55f * (1f - num / 0.18f));
					GUI.DrawTexture(r, (Texture)(object)WhiteTex());
				}
				float num2 = Mathf.Clamp01(num / 0.12f);
				float num3 = ((num <= 0.12f) ? 1f : Mathf.Clamp01(1f - (num - 0.12f) / 0.48f));
				float num4 = ((Rect)(ref r)).height * 1.9f * num2;
				float num5 = ((Rect)(ref r)).x + ((Rect)(ref r)).width * 0.18f;
				float num6 = ((Rect)(ref r)).width * 0.64f;
				int num7 = 10;
				for (int i = 0; i < num7; i++)
				{
					float num8 = (float)i / (float)num7;
					float num9 = ((Rect)(ref r)).y - num4 * num8;
					float num10 = ((Rect)(ref r)).y - num4 * (num8 + 1f / (float)num7);
					float num11 = num3 * (1f - num8) * 0.85f;
					GUI.color = new Color(value2.r, value2.g, value2.b, num11);
					GUI.DrawTexture(new Rect(num5, num10, num6, num9 - num10 + 1f), (Texture)(object)WhiteTex());
				}
				GUI.color = Color.white;
			}
		}

		private static string KeyLabel(int midi)
		{
			try
			{
				int num = midi - 48 - _octave * 12;
				if (num < 0)
				{
					return "";
				}
				string text = Exact(WhiteRowZ, WhiteSemiZ, num);
				if (text != null)
				{
					return text;
				}
				text = Exact(WhiteRowA, WhiteSemiA, num);
				if (text != null)
				{
					return text;
				}
				text = Exact(WhiteRowQ, WhiteSemiQ, num);
				if (text != null)
				{
					return text;
				}
				text = Exact(BlackRow, BlackSemi, num);
				if (text != null)
				{
					return text;
				}
			}
			catch
			{
			}
			return "";
		}

		private static string Exact(string row, int[] semis, int rel)
		{
			for (int i = 0; i < semis.Length && i < row.Length; i++)
			{
				if (semis[i] == rel)
				{
					return row[i].ToString().ToUpperInvariant();
				}
			}
			return null;
		}

		private static string MatchRow(string row, int[] semis, int rel, int baseSemi)
		{
			for (int i = 0; i < semis.Length && i < row.Length; i++)
			{
				int num = rel - semis[i];
				if (num >= 0 && num % 12 == 0 && num / 12 <= 6)
				{
					return row[i].ToString().ToUpperInvariant();
				}
			}
			return null;
		}

		private static string MatchRow(string row, int[] semis, int rel)
		{
			for (int i = 0; i < semis.Length && i < row.Length; i++)
			{
				int num = rel - semis[i];
				if (num >= 0 && num % 12 == 0 && num / 12 <= 6)
				{
					return row[i].ToString().ToUpperInvariant();
				}
			}
			return null;
		}

		private static string NoteNameOf(int whiteIndex)
		{
			int[] array = new int[7] { 0, 2, 4, 5, 7, 9, 11 };
			int num = whiteIndex / 7;
			int num2 = whiteIndex % 7;
			return NoteName(48 + _octave * 12 + num * 12 + array[num2]);
		}

		private static string NoteName(int midi)
		{
			int num = (midi % 12 + 12) % 12;
			int num2 = midi / 12 - 1;
			return NoteNames[num] + num2;
		}

		private static bool HandlePlayKey(Event e)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Invalid comparison between Unknown and I4
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Invalid comparison between Unknown and I4
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if ((int)e.keyCode == 44)
			{
				_octave = Mathf.Max(0, _octave - 1);
				Log.LogInfo((object)("[钢琴] 八度=" + _octave));
				return false;
			}
			if ((int)e.keyCode == 46)
			{
				_octave = Mathf.Min(6, _octave + 1);
				Log.LogInfo((object)("[钢琴] 八度=" + _octave));
				return false;
			}
			string text = CharFor(e.keyCode);
			if (text.Length == 0)
			{
				return false;
			}
			char value = char.ToLowerInvariant(text[0]);
			int num = -1;
			int num2 = WhiteRowZ.IndexOf(value);
			int num3 = WhiteRowA.IndexOf(value);
			int num4 = WhiteRowQ.IndexOf(value);
			int num5 = BlackRow.IndexOf(value);
			if (num2 >= 0)
			{
				num = 48 + _octave * 12 + WhiteSemiZ[num2];
			}
			else if (num3 >= 0)
			{
				num = 48 + _octave * 12 + WhiteSemiA[num3];
			}
			else if (num4 >= 0)
			{
				num = 48 + _octave * 12 + WhiteSemiQ[num4];
			}
			else
			{
				if (num5 < 0)
				{
					if (_seenKeys <= 30)
					{
						Log.LogInfo((object)("[钢琴] 键位未映射: " + text));
					}
					return false;
				}
				num = 48 + _octave * 12 + BlackSemi[num5];
			}
			PlayNote(num);
			return true;
		}

		private static string CharFor(KeyCode k)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Invalid comparison between Unknown and I4
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Invalid comparison between Unknown and I4
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Invalid comparison between Unknown and I4
			//IL_0022: 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_0026: 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_0040: 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)
			if ((int)k == 59)
			{
				return ";";
			}
			if ((int)k == 39)
			{
				return "'";
			}
			if ((int)k >= 97 && (int)k <= 122)
			{
				return ((char)(97 + (k - 97))).ToString();
			}
			if ((int)k >= 48 && (int)k <= 57)
			{
				return ((char)(48 + (k - 48))).ToString();
			}
			return "";
		}

		private static void PlayByIndexRaw(int idx)
		{
			//IL_010b: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			//IL_0067: 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)
			MovePianoToPlayer();
			if ((Object)(object)_logic == (Object)null || _keyCount <= 0)
			{
				Log.LogWarning((object)"[钢琴测试] 琴未就绪,无法测试");
				return;
			}
			if (_pianoInTruck == null || !_pianoInTruck.Value)
			{
				try
				{
					if ((Object)(object)_grab != (Object)null && (Object)(object)PlayerAvatar.instance != (Object)null)
					{
						_grab.midPoint = ((Component)PlayerAvatar.instance).transform.position;
					}
				}
				catch
				{
				}
			}
			bool flag = false;
			if ((Object)(object)_pianoView != (Object)null && _pianoView.ViewID != 0 && PhotonNetwork.InRoom)
			{
				try
				{
					_pianoView.RPC("MusicKeyPressedRPC", (RpcTarget)0, new object[2] { idx, 0 });
					flag = true;
				}
				catch (Exception ex)
				{
					Log.LogWarning((object)("[钢琴测试] RPC 失败: " + ex.GetType().Name + " " + ex.Message));
				}
				try
				{
					PhotonNetwork.RaiseEvent(HostNoteEventCode, (object)new byte[1] { (byte)idx }, new RaiseEventOptions
					{
						Receivers = (ReceiverGroup)0
					}, SendOptions.SendReliable);
				}
				catch
				{
				}
			}
			if (!flag)
			{
				flag = PlayViaPlayKey(idx);
			}
			Log.LogInfo((object)("[钢琴测试] idx=" + idx + " 播放=" + (flag ? "成功" : "失败")));
		}

		private static void MeasureRange()
		{
			try
			{
				if ((Object)(object)_logic == (Object)null)
				{
					Log.LogWarning((object)"[钢琴测量] 琴未就绪");
					return;
				}
				IList list = ((_keysField == null) ? null : (_keysField.GetValue(_logic) as IList));
				if (list == null || list.Count == 0)
				{
					Log.LogWarning((object)"[钢琴测量] musicKeys 为空");
					return;
				}
				int count = list.Count;
				string[] array = new string[count];
				int[] array2 = new int[count];
				for (int i = 0; i < count; i++)
				{
					object? obj = list[i];
					Sound val = (Sound)((obj is Sound) ? obj : null);
					array[i] = ((val != null && val.Sounds != null && val.Sounds.Length != 0 && (Object)(object)val.Sounds[0] != (Object)null) ? ((Object)val.Sounds[0]).name : "?");
					array2[i] = ParseNoteMidi(array[i]);
				}
				Log.LogInfo((object)("[钢琴测量] 音源表: " + string.Join(", ", Array.ConvertAll(array, (string x) => x))));
				float[] array3 = new float[count];
				for (int num = 0; num < count; num++)
				{
					ref float reference = ref array3[num];
					object? obj2 = list[num];
					reference = ((Sound)(((obj2 is Sound) ? obj2 : null)?)).Pitch ?? (-1f);
				}
				StringBuilder stringBuilder = new StringBuilder();
				for (int num2 = 0; num2 <= 108; num2++)
				{
					PlayViaPlayKey(num2);
					int num3 = -1;
					float num4 = 0f;
					for (int num5 = 0; num5 < count; num5++)
					{
						object? obj3 = list[num5];
						Sound val2 = (Sound)((obj3 is Sound) ? obj3 : null);
						if (val2 != null && !(Mathf.Abs(val2.Pitch - array3[num5]) < 0.0001f))
						{
							num3 = num5;
							num4 = val2.Pitch;
							array3[num5] = val2.Pitch;
						}
					}
					if (num3 < 0)
					{
						stringBuilder.Append(num2 + ":同前 ");
						continue;
					}
					int num6 = Mathf.RoundToInt(12f * Mathf.Log(num4, 2f));
					int num7 = array2[num3] + num6;
					stringBuilder.Append(num2 + ":" + array[num3] + "+" + num6 + "=" + num7 + " ");
					if (num2 % 6 == 5)
					{
						Log.LogInfo((object)("[钢琴测量] " + stringBuilder.ToString()));
						stringBuilder.Length = 0;
					}
				}
				if (stringBuilder.Length > 0)
				{
					Log.LogInfo((object)("[钢琴测量] " + stringBuilder.ToString()));
				}
				Log.LogInfo((object)"[钢琴测量] 完成");
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[钢琴测量] 异常: " + ex.GetType().Name + " " + ex.Message));
			}
		}

		private static int ParseNoteMidi(string name)
		{
			try
			{
				if (string.IsNullOrEmpty(name))
				{
					return -1;
				}
				int num = name.LastIndexOf('_');
				string text = ((num >= 0) ? name.Substring(num + 1) : name);
				int num2 = text[text.Length - 1] - 48;
				string text2 = text.Substring(0, text.Length - 1);
				int num3;
				if (text2 != null)
				{
					int length = text2.Length;
					if (length == 1)
					{
						switch (text2[0])
						{
						case 'C':
							break;
						case 'D':
							goto IL_0126;
						case 'E':
							goto IL_0130;
						case 'F':
							goto IL_0135;
						case 'G':
							goto IL_013f;
						case 'A':
							goto IL_0149;
						case 'B':
							goto IL_0155;
						default:
							goto IL_015b;
						}
						num3 = 0;
						goto IL_0160;
					}
					if (length == 2)
					{
						switch (text2[0])
						{
						case 'C':
							break;
						case 'D':
							goto IL_00e0;
						case 'F':
							goto IL_00ef;
						case 'G':
							goto IL_00fe;
						case 'A':
							goto IL_010d;
						default:
							goto IL_015b;
						}
						if (text2 == "C#")
						{
							num3 = 1;
							goto IL_0160;
						}
					}
				}
				goto IL_015b;
				IL_0160:
				return 12 * (num2 + 1) + num3;
				IL_00fe:
				if (!(text2 == "G#"))
				{
					goto IL_015b;
				}
				num3 = 8;
				goto IL_0160;
				IL_010d:
				if (!(text2 == "A#"))
				{
					goto IL_015b;
				}
				num3 = 10;
				goto IL_0160;
				IL_015b:
				return -1;
				IL_00ef:
				if (!(text2 == "F#"))
				{
					goto IL_015b;
				}
				num3 = 6;
				goto IL_0160;
				IL_00e0:
				if (!(text2 == "D#"))
				{
					goto IL_015b;
				}
				num3 = 3;
				goto IL_0160;
				IL_0149:
				num3 = 9;
				goto IL_0160;
				IL_0155:
				num3 = 11;
				goto IL_0160;
				IL_013f:
				num3 = 7;
				goto IL_0160;
				IL_0126:
				num3 = 2;
				goto IL_0160;
				IL_0130:
				num3 = 4;
				goto IL_0160;
				IL_0135:
				num3 = 5;
				goto IL_0160;
			}
			catch
			{
				return -1;
			}
		}

		private static IEnumerator PlaySong(Song song)
		{
			if (song == null)
			{
				yield break;
			}
			_songPlaying = true;
			_songPlayingName = song.Name;
			try
			{
				int num = 127;
				for (int i = 0; i < song.Notes.Count; i++)
				{
					if (song.Notes[i].Midi < num)
					{
						num = song.Notes[i].Midi;
					}
				}
				int num2 = Mathf.Clamp((num - 48) / 12, 0, 6);
				if (num2 != _octave)
				{
					_octave = num2;
					Log.LogInfo((object)("[钢琴] 键盘八度自动切到 " + num2 + "(对齐曲子最低音)"));
				}
			}
			catch
			{
			}
			Log.LogInfo((object)("[钢琴] 开始演奏: " + song.Name + "(" + song.Notes.Count + " 个音,时长 " + song.Duration.ToString("F1") + "s)"));
			float start = Time.unscaledTime;
			int next = 0;
			while (_songPlaying && next < song.Notes.Count)
			{
				NoteEvent e = song.Notes[next];
				float due = start + e.Time;
				while (Time.unscaledTime < due && _songPlaying)
				{
					yield return null;
				}
				if (!_songPlaying)
				{
					break;
				}
				PlayNote(e.Midi);
				int j;
				for (j = next + 1; j < song.Notes.Count && song.Notes[j].Time <= e.Time + 0.001f; j++)
				{
					PlayNote(song.Notes[j].Midi);
				}
				next = j;
			}
			_songPlaying = false;
			Log.LogInfo((object)("[钢琴] 演奏结束: " + song.Name));
		}

		private static IEnumerator TestScale()
		{
			Log.LogInfo((object)"[钢琴测试] 开始:idx 0,6,12,...,108(每 0.4 秒一个,注意听音高变化)");
			for (int idx = 0; idx <= 108; idx += 6)
			{
				PlayByIndexRaw(idx);
				yield return (object)new WaitForSecondsRealtime(0.4f);
			}
			Log.LogInfo((object)"[钢琴测试] 结束");
		}

		private static void PlayNote(int midi)
		{
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_logic == (Object)null || _keyCount <= 0)
			{
				if (_notReadyLogged < 3)
				{
					_notReadyLogged++;
					Log.LogWarning((object)("[钢琴] 琴未就绪(logic=" + ((Object)(object)_logic != (Object)null) + " 键数=" + _keyCount + ")"));
				}
				return;
			}
			if (midi < 48 || midi > 121)
			{
				if (_played < 5)
				{
					_played++;
					Log.LogWarning((object)("[钢琴] 超出音域:MIDI=" + midi + "(可用 " + 48 + "~" + 121 + ")"));
				}
				return;
			}
			int num = midi - 48;
			int num2 = InstrOct();
			int num3 = InstrKeyLimit();
			int num4 = num / 4;
			int num5 = num2 * 3 - 1;
			if (num4 > num5)
			{
				num4 = num5;
			}
			int num6 = midi - (48 + 4 * num4);
			int num7 = num2 * num4 + num6;
			if (num7 < 0 || num7 >= num3)
			{
				if (_played < 5)
				{
					_played++;
					Log.LogWarning((object)("[钢琴] 索引越界:MIDI=" + midi + " idx=" + num7 + " 上限=" + num3));
				}
				return;
			}
			_played++;
			FxHit(midi);
			if (_played <= 10 || _played % 15 == 0)
			{
				Log.LogInfo((object)("[钢琴] 演奏 " + NoteName(midi) + " (MIDI " + midi + " → idx " + num7 + ") 第 " + _played + " 次"));
			}
			bool flag = false;
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient && !_nonHostLocalLogged)
			{
				_nonHostLocalLogged = true;
				Log.LogInfo((object)"[钢琴] 客机模式:本机发声 + 音符经房主中继(房主需安装本模组才能让所有人听到)");
			}
			MovePianoToPlayer();
			if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient && !_nonHostWarned)
			{
				_nonHostWarned = true;
				Log.LogWarning((object)"[钢琴] 你是客机:原版 RPC 会被 MasterOnlyRPC 拒绝 → 只有你自己能听到(本地2D)。要让别人听到,需房主也安装本模组。");
			}
			try
			{
				if ((Object)(object)_grab != (Object)null && (Object)(object)PlayerAvatar.instance != (Object)null)
				{
					_grab.midPoint = ((Component)PlayerAvatar.instance).transform.position;
				}
			}
			catch
			{
			}
			if (PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient && (Object)(object)_pianoView != (Object)null && _pianoView.ViewID != 0 && _useVanillaRpc != null && _useVanillaRpc.Value)
			{
				try
				{
					_pianoView.RPC("MusicKeyPressedRPC", (RpcTarget)0, new object[2] { num7, 0 });
					flag = true;
				}
				catch (Exception ex)
				{
					if (!_rpcFailLogged)
					{
						_rpcFailLogged = true;
						Log.LogWarning((object)("[钢琴] 原版 RPC 失败:" + ex.GetType().Name + " " + ex.Message));
					}
				}
			}
			else
			{
				if (PhotonNetwork.InRoom && !PhotonNetwork.IsMasterClient)
				{
					SendNoteToHost(num7);
				}
				if (PlayViaPlayKey(num7))
				{
					flag = true;
				}
			}
			if (!flag || (_localAlways != null && _localAlways.Value))
			{
				PlayLocal(num7);
			}
		}

		private static void PlayLocal(int idx)
		{
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Expected O, but got Unknown
			//IL_013d: 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)
			try
			{
				IList list = ((_keysField == null) ? null : (_keysField.GetValue(_logic) as IList));
				if (list == null || idx < 0 || idx >= list.Count)
				{
					V("本地播放:键列表不可用");
					return;
				}
				object? obj = list[idx];
				Sound val = (Sound)((obj is Sound) ? obj : null);
				if (val == null)
				{
					V("本地播放:Sound 为空");
					return;
				}
				AudioClip val2 = null;
				if (val.Sounds != null && val.Sounds.Length != 0)
				{
					val2 = val.Sounds[Random.Range(0, val.Sounds.Length)];
				}
				if ((Object)(object)val2 == (Object)null && (Object)(object)val.Source != (Object)null)
				{
					val2 = val.Source.clip;
				}
				if ((Object)(object)val2 == (Object)null)
				{
					if (_played <= 3)
					{
						Log.LogWarning((object)"[钢琴] 本地播放失败:该键没有 clip");
					}
					return;
				}
				if ((Object)(object)_localAudio == (Object)null)
				{
					GameObject val3 = new GameObject("SimplePiano_LocalAudio");
					Object.DontDestroyOnLoad((Object)val3);
					_localAudio = val3.AddComponent<AudioSource>();
					_localAudio.spatialBlend = 0f;
					_localAudio.playOnAwake = false;
				}
				((Component)_localAudio).transform.position = (((Object)(object)PlayerAvatar.instance != (Object)null) ? ((Component)PlayerAvatar.instance).transform.position : Vector3.zero);
				_localAudio.pitch = 1f;
				_localAudio.volume = Mathf.Clamp01((_volume == null) ? 0.8f : _volume.Value);
				_localAudio.PlayOneShot(val2);
				V("本地播放 " + ((Object)val2).name);
			}
			catch (Exception ex)
			{
				V("本地播放异常: " + ex.Message);
			}
		}
	}
	internal static class InputPrefixes
	{
		public static bool BoolPrefix(ref bool __result)
		{
			if (Plugin.PanelOpen)
			{
				__result = false;
				return false;
			}
			return true;
		}

		public static bool FloatPrefix(ref float __result)
		{
			if (Plugin.PanelOpen)
			{
				__result = 0f;
				return false;
			}
			return true;
		}

		public static bool SkipPrefix()
		{
			return !Plugin.PanelOpen;
		}

		public static bool PropertyBoolPrefix(ref bool __result)
		{
			if (Plugin.PanelOpen)
			{
				__result = false;
				return false;
			}
			return true;
		}

		public static bool Vector2Prefix(ref Vector2 __result)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.PanelOpen)
			{
				__result = Vector2.zero;
				return false;
			}
			return true;
		}
	}
	internal static class InputBlockPatches
	{
		[HarmonyPatch(typeof(InputManager), "KeyDown")]
		private static class PKeyDown
		{
			private static bool Prefix(ref bool __result)
			{
				if (Plugin.PanelOpen)
				{
					__result = false;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(InputManager), "KeyHold")]
		private static class PKeyHold
		{
			private static bool Prefix(ref bool __result)
			{
				if (Plugin.PanelOpen)
				{
					__result = false;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(InputManager), "KeyUp")]
		private static class PKeyUp
		{
			private static bool Prefix(ref bool __result)
			{
				if (Plugin.PanelOpen)
				{
					__result = false;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(InputManager), "GetMouseX")]
		private static class PMouseX
		{
			private static bool Prefix(ref float __result)
			{
				if (Plugin.PanelOpen)
				{
					__result = 0f;
					return false;
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(InputManager), "GetMouseY")]
		private static class PMouseY
		{
			private static bool Prefix(ref float __result)
			{
				if (Plugin.PanelOpen)
				{
					__result = 0f;
					return false;
				}
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(MusicalValuableLogic), "MusicKeyPressedRPC")]
	internal static class PianoDedupPatch
	{
		internal static bool Prefix(int keyIndex)
		{
			try
			{
				if (!PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient)
				{
					return true;
				}
				if (Plugin.LastLocalIdx == keyIndex && Time.unscaledTime - Plugin.LastLocalAt < 0.35f)
				{
					return false;
				}
			}
			catch
			{
			}
			return true;
		}
	}
	internal struct NoteEvent
	{
		public float Time;

		public int Midi;

		public float Length;
	}
	internal sealed class Song
	{
		public string Name;