Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of SimplePiano v0.1.1
plugins/SimplePiano.dll
Decompiled 2 minutes agousing 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 { [BepInPlugin("cn_xc.SimplePiano", "Simple Piano", "0.1.1")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; internal const byte NoteEventCode = 173; 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<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 const string PianoPrefabPath = "Valuables/05 Wide/Valuable Manor Piano"; private const int PianoBaseMidi = 48; private const int PianoMaxMidi = 121; private const int PianoKeyLimit = 108; 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 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 GUIStyle _keyStyle; 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_00fd: 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_0189: Expected O, but got Unknown //IL_01b2: Unknown result type (might be due to invalid IL or missing references) //IL_01bc: Expected O, but got Unknown //IL_020f: Unknown result type (might be due to invalid IL or missing references) //IL_0219: Expected O, but got Unknown //IL_0313: Unknown result type (might be due to invalid IL or missing references) //IL_0318: Unknown result type (might be due to invalid IL or missing references) //IL_031e: Expected O, but got Unknown //IL_031e: Unknown result type (might be due to invalid IL or missing references) //IL_0329: Unknown result type (might be due to invalid IL or missing references) //IL_032f: Expected O, but got Unknown //IL_0364: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; MigrateOldConfig(); _inst = this; try { PhotonNetwork.NetworkingClient.EventReceived += OnPhotonEvent; _eventHooked = true; } catch { } try { _songs = Songs.LoadAll(); 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)112, 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, "是否显示卡车里的钢琴本体(有模型但不能碰/不能搬)。显存紧张时建议关闭。"); _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 已加载(实测音域映射:idx = 6*((midi-48)/4)+(midi-48)%4,可用 48~121)"); 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 && _callerScanTries < 1 && !(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 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_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00cf: Unknown result type (might be due to invalid IL or missing references) //IL_02f4: 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) { _piano = PhotonNetwork.Instantiate("Valuables/05 Wide/Valuable Manor Piano", val, Quaternion.identity, (byte)0, (object[])null); } else { GameObject val2 = Resources.Load<GameObject>("Valuables/05 Wide/Valuable Manor Piano"); if ((Object)(object)val2 == (Object)null) { if (!_spawnFailLogged) { _spawnFailLogged = true; Log.LogWarning((object)"[钢琴] 单人模式:Resources 里找不到钢琴 prefab"); } return; } _piano = Object.Instantiate<GameObject>(val2, 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[] componentsInChildren = _piano.GetComponentsInChildren<Collider>(true); for (int i = 0; i < componentsInChildren.Length; i++) { componentsInChildren[i].enabled = false; } bool flag = _showModel != null && _showModel.Value; try { if (!_vramLogged) { _vramLogged = true; Log.LogInfo((object)("[钢琴] 显卡显存=" + SystemInfo.graphicsMemorySize + "MB(显示模型=" + flag + ")")); } } catch { } if (!flag) { Renderer[] componentsInChildren2 = _piano.GetComponentsInChildren<Renderer>(true); for (int i = 0; i < componentsInChildren2.Length; i++) { componentsInChildren2[i].enabled = false; } } Rigidbody component = _piano.GetComponent<Rigidbody>(); if ((Object)(object)component != (Object)null) { component.isKinematic = true; component.detectCollisions = false; } PhysGrabObject[] componentsInChildren3 = _piano.GetComponentsInChildren<PhysGrabObject>(true); for (int i = 0; i < componentsInChildren3.Length; i++) { ((Behaviour)componentsInChildren3[i]).enabled = false; } PhysGrabObjectGrabArea[] componentsInChildren4 = _piano.GetComponentsInChildren<PhysGrabObjectGrabArea>(true); for (int i = 0; i < componentsInChildren4.Length; i++) { ((Behaviour)componentsInChildren4[i]).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(); 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.SimplePiano", _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.SimplePiano", _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_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) try { if (e != null && e.Code == 173 && PhotonNetwork.IsMasterClient && !((Object)(object)_pianoView == (Object)null) && _pianoView.ViewID != 0 && e.CustomData is byte[] array && array.Length >= 1) { int num = array[0]; if ((Object)(object)_grab != (Object)null) { _grab.midPoint = _piano.transform.position; } _pianoView.RPC("MusicKeyPressedRPC", (RpcTarget)1, new object[2] { num, 0 }); } } 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((byte)173, (object)new byte[1] { (byte)idx }, new RaiseEventOptions { Receivers = (ReceiverGroup)2 }, SendOptions.SendUnreliable); } 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_019b: Unknown result type (might be due to invalid IL or missing references) //IL_01a2: Invalid comparison between Unknown and I4 //IL_0207: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Invalid comparison between Unknown and I4 //IL_0268: Unknown result type (might be due to invalid IL or missing references) //IL_026f: Invalid comparison between Unknown and I4 //IL_0272: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Invalid comparison between Unknown and I4 //IL_0300: Unknown result type (might be due to invalid IL or missing references) //IL_0305: 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; Log.LogInfo((object)("[钢琴] 重新扫描曲目: " + _songs.Count + " 首")); current.Use(); return; } if ((int)current.keyCode == 91) { if (_songs.Count > 0) { _songIndex = (_songIndex - 1 + _songs.Count) % _songs.Count; Log.LogInfo((object)("[钢琴] 选曲: " + _songs[_songIndex].Name)); } current.Use(); return; } if ((int)current.keyCode == 93) { if (_songs.Count > 0) { _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_0090: Unknown result type (might be due to invalid IL or missing references) //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_017d: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: 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_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0324: Unknown result type (might be due to invalid IL or missing references) //IL_02dc: 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_0458: Unknown result type (might be due to invalid IL or missing references) //IL_04ea: Unknown result type (might be due to invalid IL or missing references) //IL_04f4: Unknown result type (might be due to invalid IL or missing references) //IL_0500: Unknown result type (might be due to invalid IL or missing references) //IL_052a: Unknown result type (might be due to invalid IL or missing references) //IL_0551: Unknown result type (might be due to invalid IL or missing references) //IL_068a: Unknown result type (might be due to invalid IL or missing references) //IL_05f5: Unknown result type (might be due to invalid IL or missing references) //IL_05ff: Unknown result type (might be due to invalid IL or missing references) //IL_060b: Unknown result type (might be due to invalid IL or missing references) //IL_063c: Unknown result type (might be due to invalid IL or missing references) //IL_0660: 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 - 78f, w, 20f), "钢琴 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 | 黑键 1~8"); GUI.Label(new Rect(x, y - 58f, w, 20f), "八度 = " + _octave + "(, . 切换) P 关闭 F3 拖动 F7 召唤钢琴 F6 重扫曲目 F2 拖动"); float num2 = y - 36f; if (GUI.Button(new Rect(x, num2, 34f, 22f), "↻")) { _songs = Songs.LoadAll(); _songIndex = 0; Log.LogInfo((object)("[钢琴] 重扫曲目: " + _songs.Count)); } if (GUI.Button(new Rect(x + 38f, num2, 30f, 22f), "◀") && _songs.Count > 0) { _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) { _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)) { _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) { GUI.Label(new Rect(x + 156f + 616f, num2, 200f, 22f), "第 " + (num5 + 1) + "/" + Mathf.CeilToInt((float)_songs.Count / 4f) + " 页"); } string text = ((_songs.Count == 0) ? "曲目: 无(放进 Songs 目录后按 ↻)" : ("当前曲目 " + (_songIndex + 1) + "/" + _songs.Count + ": " + _songs[_songIndex].Name + (_songPlaying ? " ▶ 播放中(Enter/■ 停止)" : " (点名字选择,▶ 播放)"))); GUI.Label(new Rect(x, num2 + 24f, w, 20f), text); num2 += 24f; float num9 = w / (float)num; float unscaledTime = Time.unscaledTime; int num10 = 48 + _octave * 12; float num11 = y + 26f; 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; } 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_002d: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003b: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: 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) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Unknown result type (might be due to invalid IL or missing references) //IL_0138: Unknown result type (might be due to invalid IL or missing references) //IL_013e: Unknown result type (might be due to invalid IL or missing references) //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_0161: 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) if (!_fx.TryGetValue(midi, out var value)) { return; } float num = now - value.Key; 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_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)); } } 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; 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 i; for (i = next + 1; i < song.Notes.Count && song.Notes[i].Time <= e.Time + 0.001f; i++) { PlayNote(song.Notes[i].Midi); } next = i; } _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_0292: Unknown result type (might be due to invalid IL or missing references) //IL_0297: 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) / 4; if (num > 17) { num = 17; } int num2 = midi - (48 + 4 * num); int num3 = 6 * num + num2; if (num3 < 0 || num3 >= 108) { if (_played < 5) { _played++; Log.LogWarning((object)("[钢琴] 索引越界:MIDI=" + midi + " idx=" + num3 + " 上限=" + 108)); } return; } _played++; FxHit(midi); if (_played <= 10 || _played % 15 == 0) { Log.LogInfo((object)("[钢琴] 演奏 " + NoteName(midi) + " (MIDI " + midi + " → idx " + num3 + ") 第 " + _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] { num3, 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(num3); } if (PlayViaPlayKey(num3)) { flag = true; } } if (!flag || (_localAlways != null && _localAlways.Value)) { PlayLocal(num3); } } 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; } } } internal struct NoteEvent { public float Time; public int Midi; public float Length; } internal sealed class Song { public string Name; public string Path; public List<NoteEvent> Notes = new List<NoteEvent>(); public float Duration { get { float num = 0f; for (int i = 0; i < Notes.Count; i++) { float num2 = Notes[i].Time + Notes[i].Length; if (num2 > num) { num = num2; } } return num; } } } internal static class Songs { private struct RawEvent { public long Tick; public int Midi; public bool On; } public static string FolderPath => Path.Combine(Paths.ConfigPath, "SimplePiano", "Songs"); public static void EnsureFolder() { try { Directory.CreateDirectory(FolderPath); } catch { } } public static List<Song> LoadAll() { List<Song> list = new List<Song>(); EnsureFolder(); try { string[] files = Directory.GetFiles(FolderPath); foreach (string path in files) { string text = Path.GetExtension(path).ToLowerInvariant(); if (text != ".mid" && text != ".midi" && text != ".txt") { continue; } try { Song song = ((text == ".txt") ? LoadTxt(path) : LoadMidi(path)); if (song != null && song.Notes.Count > 0) { list.Add(song); } } catch { } } } catch { } list.Sort((Song a, Song b) => string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase)); return list; } private static Song LoadTxt(string path) { Song song = new Song { Name = Path.GetFileNameWithoutExtension(path), Path = path }; string[] array = File.ReadAllLines(path); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length == 0 || text.StartsWith("#")) { continue; } string[] array2 = text.Split(new char[4] { ' ', '\t', ',', ';' }, StringSplitOptions.RemoveEmptyEntries); if (array2.Length < 2) { continue; } float result = 0.3f; if (float.TryParse(array2[0], out var result2) && int.TryParse(array2[1], out var result3)) { if (array2.Length >= 3) { float.TryParse(array2[2], out result); } song.Notes.Add(new NoteEvent { Time = result2 / 1000f, Midi = result3, Length = result / 1000f }); } } song.Notes.Sort((NoteEvent a, NoteEvent b) => a.Time.CompareTo(b.Time)); return song; } private static Song LoadMidi(string path) { byte[] array = File.ReadAllBytes(path); if (array.Length < 14 || ReadAscii(array, 0, 4) != "MThd") { return null; } int num = ReadInt32(array, 4); ReadInt16(array, 8); int num2 = ReadInt16(array, 10); int division = ReadInt16(array, 12); Song song = new Song { Name = Path.GetFileNameWithoutExtension(path), Path = path }; if (division <= 0) { return song; } int i = 8 + num; List<KeyValuePair<long, int>> tempos = new List<KeyValuePair<long, int>>(); List<RawEvent> list = new List<RawEvent>(); for (int j = 0; j < num2; j++) { if (i + 8 > array.Length) { break; } for (; i + 8 <= array.Length && ReadAscii(array, i, 4) != "MTrk"; i++) { } if (i + 8 > array.Length) { break; } int num3 = ReadInt32(array, i + 4); int p = i + 8; int num4 = Math.Min(array.Length, p + num3); long num5 = 0L; byte b = 0; while (p < num4) { num5 += ReadVarLen(array, ref p); if (p >= num4) { break; } byte b2 = array[p]; if (b2 < 128) { b2 = b; } else { p++; b = b2; } int num6 = b2 & 0xF0; switch (b2) { case byte.MaxValue: break; case 240: case 247: { int num8 = ReadVarLen(array, ref p); p += num8; continue; } default: switch (num6) { case 128: case 144: { int midi = array[p++]; int num7 = ((p < num4) ? array[p++] : 0); bool flag = num6 == 144 && num7 > 0; list.Add(new RawEvent { Tick = num5, Midi = midi, On = flag }); break; } case 192: case 208: p++; break; default: p += 2; break; } continue; } if (p >= num4) { break; } byte num9 = array[p++]; int num10 = ReadVarLen(array, ref p); if (num9 == 81 && num10 == 3 && p + 2 < array.Length) { int value = (array[p] << 16) | (array[p + 1] << 8) | array[p + 2]; tempos.Add(new KeyValuePair<long, int>(num5, value)); } p += num10; } i = num4; } if (list.Count == 0) { return song; } tempos.Sort((KeyValuePair<long, int> a, KeyValuePair<long, int> keyValuePair2) => a.Key.CompareTo(keyValuePair2.Key)); if (tempos.Count == 0 || tempos[0].Key != 0L) { tempos.Insert(0, new KeyValuePair<long, int>(0L, 500000)); } Func<long, float> func = delegate(long tick) { double num11 = 0.0; long num12 = 0L; int num13 = 500000; for (int k = 0; k < tempos.Count; k++) { long key = tempos[k].Key; if (key >= tick) { break; } num11 += (double)(key - num12) * (double)num13 / 1000000.0 / (double)division; num12 = key; num13 = tempos[k].Value; } num11 += (double)(tick - num12) * (double)num13 / 1000000.0 / (double)division; return (float)num11; }; Dictionary<int, Queue<KeyValuePair<long, float>>> dictionary = new Dictionary<int, Queue<KeyValuePair<long, float>>>(); list.Sort((RawEvent a, RawEvent rawEvent) => a.Tick.CompareTo(rawEvent.Tick)); foreach (RawEvent item in list) { Queue<KeyValuePair<long, float>> value3; if (item.On) { if (!dictionary.TryGetValue(item.Midi, out var value2)) { value2 = new Queue<KeyValuePair<long, float>>(); dictionary[item.Midi] = value2; } value2.Enqueue(new KeyValuePair<long, float>(item.Tick, func(item.Tick))); } else if (dictionary.TryGetValue(item.Midi, out value3) && value3.Count > 0) { KeyValuePair<long, float> keyValuePair = value3.Dequeue(); float length = Math.Max(0.05f, func(item.Tick) - keyValuePair.Value); song.Notes.Add(new NoteEvent { Time = keyValuePair.Value, Midi = item.Midi, Length = length }); } } song.Notes.Sort((NoteEvent a, NoteEvent noteEvent) => a.Time.CompareTo(noteEvent.Time)); return song; } private static string ReadAscii(byte[] d, int p, int n) { StringBuilder stringBuilder = new StringBuilder(n); for (int i = 0; i < n && p + i < d.Length; i++) { stringBuilder.Append((char)d[p + i]); } return stringBuilder.ToString(); } private static int ReadInt32(byte[] d, int p) { return (d[p] << 24) | (d[p + 1] << 16) | (d[p + 2] << 8) | d[p + 3]; } private static int ReadInt16(byte[] d, int p) { return (d[p] << 8) | d[p + 1]; } private static int ReadVarLen(byte[] d, ref int p) { int num = 0; for (int i = 0; i < 4; i++) { if (p >= d.Length) { break; } byte b = d[p++]; num = (num << 7) | (b & 0x7F); if ((b & 0x80) == 0) { break; } } return num; } } }