Decompiled source of Instruments4Music v2.1.0

Instruments4Music.dll

Decompiled 6 months ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Instruments4Music.NetcodePatcher;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")]
[assembly: AssemblyCompany("Instruments4Music")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Add instruments to play music.")]
[assembly: AssemblyFileVersion("0.5.0.0")]
[assembly: AssemblyInformationalVersion("0.5.0+1db909e8ff82555010a3cb2aad7ba8ddc2e5ae7c")]
[assembly: AssemblyProduct("Instruments4Music")]
[assembly: AssemblyTitle("Instruments4Music")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.5.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 Instruments4Music
{
	public class InputActions : LcInputActions
	{
		[InputAction("<Keyboard>/backslash", Name = "SwitchTuneMethod", ActionId = "SwitchTuneMethod")]
		public InputAction? SwitchTuneMethod { get; set; }

		[InputAction("<Keyboard>/backspace", Name = "Showtime!", ActionId = "Showtime", KbmInteractions = "hold(duration = 1)")]
		public InputAction? Showtime { get; set; }

		[InputAction("<Keyboard>/escape", Name = "Curtain Call", ActionId = "CurtainCall")]
		public InputAction? CurtainCall { get; set; }

		[InputAction("<Keyboard>/leftShift", Name = "Semitone", ActionId = "Semitone")]
		public InputAction? Semitone { get; set; }

		[InputAction("<Keyboard>/space", Name = "Sustain", ActionId = "Sustain")]
		public InputAction? Sustain { get; set; }

		[InputAction("<Keyboard>/leftCtrl", Name = "Soft", ActionId = "Soft")]
		public InputAction? Soft { get; set; }

		[InputAction("<Keyboard>/tab", Name = "Change Mode", ActionId = "ChangeMode")]
		public InputAction? ChangeMode { get; set; }

		[InputAction("<Keyboard>/enter", Name = "Input Note", ActionId = "InputNote")]
		public InputAction? InputNote { get; set; }

		[InputAction("<Keyboard>/q", Name = "High C", ActionId = "HighC")]
		public InputAction? HighCKey { get; set; }

		[InputAction("<Keyboard>/w", Name = "High D", ActionId = "HighD")]
		public InputAction? HighDKey { get; set; }

		[InputAction("<Keyboard>/e", Name = "High E", ActionId = "HighE")]
		public InputAction? HighEKey { get; set; }

		[InputAction("<Keyboard>/r", Name = "High F", ActionId = "HighF")]
		public InputAction? HighFKey { get; set; }

		[InputAction("<Keyboard>/t", Name = "High G", ActionId = "HighG")]
		public InputAction? HighGKey { get; set; }

		[InputAction("<Keyboard>/y", Name = "High A", ActionId = "HighA")]
		public InputAction? HighAKey { get; set; }

		[InputAction("<Keyboard>/u", Name = "High B", ActionId = "HighB")]
		public InputAction? HighBKey { get; set; }

		[InputAction("<Keyboard>/a", Name = "Mid C", ActionId = "MidC")]
		public InputAction? MidCKey { get; set; }

		[InputAction("<Keyboard>/s", Name = "Mid D", ActionId = "MidD")]
		public InputAction? MidDKey { get; set; }

		[InputAction("<Keyboard>/d", Name = "Mid E", ActionId = "MidE")]
		public InputAction? MidEKey { get; set; }

		[InputAction("<Keyboard>/f", Name = "Mid F", ActionId = "MidF")]
		public InputAction? MidFKey { get; set; }

		[InputAction("<Keyboard>/g", Name = "Mid G", ActionId = "MidG")]
		public InputAction? MidGKey { get; set; }

		[InputAction("<Keyboard>/h", Name = "Mid A", ActionId = "MidA")]
		public InputAction? MidAKey { get; set; }

		[InputAction("<Keyboard>/j", Name = "Mid B", ActionId = "MidB")]
		public InputAction? MidBKey { get; set; }

		[InputAction("<Keyboard>/z", Name = "Low C", ActionId = "LowC")]
		public InputAction? LowCKey { get; set; }

		[InputAction("<Keyboard>/x", Name = "Low D", ActionId = "LowD")]
		public InputAction? LowDKey { get; set; }

		[InputAction("<Keyboard>/c", Name = "Low E", ActionId = "LowE")]
		public InputAction? LowEKey { get; set; }

		[InputAction("<Keyboard>/v", Name = "Low F", ActionId = "LowF")]
		public InputAction? LowFKey { get; set; }

		[InputAction("<Keyboard>/b", Name = "Low G", ActionId = "LowG")]
		public InputAction? LowGKey { get; set; }

		[InputAction("<Keyboard>/n", Name = "Low A", ActionId = "LowA")]
		public InputAction? LowAKey { get; set; }

		[InputAction("<Keyboard>/m", Name = "Low B", ActionId = "LowB")]
		public InputAction? LowBKey { get; set; }

		[InputAction("<Keyboard>/y", Name = "Low C2", ActionId = "LowC2")]
		public InputAction? LowCKey2 { get; set; }

		[InputAction("<Keyboard>/u", Name = "Low D2", ActionId = "LowD2")]
		public InputAction? LowDKey2 { get; set; }

		[InputAction("<Keyboard>/i", Name = "Low E2", ActionId = "LowE2")]
		public InputAction? LowEKey2 { get; set; }

		[InputAction("<Keyboard>/o", Name = "Low F2", ActionId = "LowF2")]
		public InputAction? LowFKey2 { get; set; }

		[InputAction("<Keyboard>/p", Name = "Low G2", ActionId = "LowG2")]
		public InputAction? LowGKey2 { get; set; }

		[InputAction("<Keyboard>/h", Name = "Low A2", ActionId = "LowA2")]
		public InputAction? LowAKey2 { get; set; }

		[InputAction("<Keyboard>/j", Name = "Low B2", ActionId = "LowB2")]
		public InputAction? LowBKey2 { get; set; }

		[InputAction("<Keyboard>/k", Name = "Mid C2", ActionId = "MidC2")]
		public InputAction? MidCKey2 { get; set; }

		[InputAction("<Keyboard>/l", Name = "Mid D2", ActionId = "MidD2")]
		public InputAction? MidDKey2 { get; set; }

		[InputAction("<Keyboard>/semicolon", Name = "Mid E2", ActionId = "MidE2")]
		public InputAction? MidEKey2 { get; set; }

		[InputAction("<Keyboard>/n", Name = "Mid F2", ActionId = "MidF2")]
		public InputAction? MidFKey2 { get; set; }

		[InputAction("<Keyboard>/m", Name = "Mid G2", ActionId = "MidG2")]
		public InputAction? MidGKey2 { get; set; }

		[InputAction("<Keyboard>/comma", Name = "Mid A2", ActionId = "MidA2")]
		public InputAction? MidAKey2 { get; set; }

		[InputAction("<Keyboard>/period", Name = "Mid B2", ActionId = "MidB2")]
		public InputAction? MidBKey2 { get; set; }

		[InputAction("<Keyboard>/slash", Name = "High C2", ActionId = "HighC2")]
		public InputAction? HighCKey2 { get; set; }

		public static string GetButtonDescription(InputAction action)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			bool localPlayerUsingController = StartOfRound.Instance.localPlayerUsingController;
			InputBinding? val = null;
			Enumerator<InputBinding> enumerator = action.bindings.GetEnumerator();
			try
			{
				if (enumerator.MoveNext())
				{
					InputBinding current = enumerator.Current;
					if (localPlayerUsingController || (!((InputBinding)(ref current)).effectivePath.StartsWith("<Keyboard>") && !((InputBinding)(ref current)).effectivePath.StartsWith("<Mouse>")))
					{
						return "";
					}
					val = current;
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			object obj;
			if (!val.HasValue)
			{
				obj = "";
			}
			else
			{
				InputBinding value = val.Value;
				obj = ((InputBinding)(ref value)).effectivePath;
			}
			string text = (string)obj;
			string[] array = text.Split("/");
			string text2 = ((array.Length > 1) ? text : "");
			if (1 == 0)
			{
			}
			string result;
			switch (text2)
			{
			case "<Mouse>/leftButton":
				result = "LΜB";
				break;
			case "<Mouse>/rightButton":
				result = "RΜB";
				break;
			case "<Keyboard>/escape":
				result = "ESC";
				break;
			case "<Keyboard>/semicolon":
				result = ";";
				break;
			case "<Keyboard>/comma":
				result = ",";
				break;
			case "<Keyboard>/period":
				result = ".";
				break;
			case "<Keyboard>/slash":
				result = "/";
				break;
			default:
			{
				object obj2;
				if (array.Length <= 1)
				{
					obj2 = "?";
				}
				else
				{
					string text3 = array[1].Substring(0, 1).ToUpper();
					string text4 = array[1];
					obj2 = text3 + text4.Substring(1, text4.Length - 1);
				}
				result = (string)obj2;
				break;
			}
			}
			if (1 == 0)
			{
			}
			return result;
		}
	}
	[BepInPlugin("com.bean.Instruments4Music", "Instruments4Music", "2.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInProcess("Lethal Company.exe")]
	public class Instruments4MusicPlugin : BaseUnityPlugin
	{
		public static Instruments4MusicPlugin? Instance;

		internal static ManualLogSource? logger;

		public static ConfigFile? config;

		internal static InputActions InputActionsInstance = new InputActions();

		public static GameObject? HudPrefab;

		public static GameObject? HudInstance;

		public static HUDManager? HudManager;

		public static HUDElement? HudElement;

		public static AudioMixer? TuneMixer;

		public static StationaryScript? Stationary;

		public static PortableScript? Portable;

		public static TuneAudioScript? Tune;

		public static PlayerControllerB Player => GameNetworkManager.Instance.localPlayerController;

		public static void AddLog(string str)
		{
			ManualLogSource? obj = logger;
			if (obj != null)
			{
				obj.LogInfo((object)str);
			}
		}

		private void Awake()
		{
			if ((Object)(object)Instance != (Object)null)
			{
				throw new Exception("More than 1 plugin instance.");
			}
			Instance = this;
			logger = ((BaseUnityPlugin)this).Logger;
			config = ((BaseUnityPlugin)this).Config;
			InstrumentsConfig.Load();
			AddLog("Plugin com.bean.Instruments4Music is loaded!");
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "com.bean.Instruments4Music");
			string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			if (directoryName != null)
			{
				string text = Path.Combine(directoryName, "instrumentassets");
				AssetBundle val = AssetBundle.LoadFromFile(text);
				HudPrefab = val.LoadAsset<GameObject>("MusicPanel");
				TuneMixer = val.LoadAsset<AudioMixer>("Tuner");
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void StartPatch(StartOfRound __instance)
		{
			ManualCameraRenderer mapScreen = __instance.mapScreen;
			object obj;
			if (mapScreen == null)
			{
				obj = null;
			}
			else
			{
				MeshRenderer mesh = mapScreen.mesh;
				obj = ((mesh != null) ? ((Component)mesh).gameObject : null);
			}
			GameObject val = (GameObject)obj;
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)val.GetComponent<StationaryScript>() == (Object)null)
				{
					Instruments4MusicPlugin.Stationary = ((Component)__instance).gameObject.AddComponent<StationaryScript>();
					Instruments4MusicPlugin.AddLog($"StationaryScript Added, owner: {((NetworkBehaviour)Instruments4MusicPlugin.Stationary).OwnerClientId}");
				}
				if ((Object)(object)val.GetComponent<PortableScript>() == (Object)null)
				{
					Instruments4MusicPlugin.Portable = ((Component)__instance).gameObject.AddComponent<PortableScript>();
					Instruments4MusicPlugin.AddLog($"PortableScript Added, owner: {((NetworkBehaviour)Instruments4MusicPlugin.Portable).OwnerClientId}");
				}
				if ((Object)(object)val.GetComponent<TuneAudioScript>() == (Object)null)
				{
					Instruments4MusicPlugin.Tune = ((Component)__instance).gameObject.AddComponent<TuneAudioScript>();
					Instruments4MusicPlugin.AddLog($"TuneAudioScript Added, owner: {((NetworkBehaviour)Instruments4MusicPlugin.Tune).OwnerClientId}");
				}
				if ((Object)(object)val.GetComponent<MusicHud>() == (Object)null)
				{
					val.AddComponent<MusicHud>();
					Instruments4MusicPlugin.AddLog("MusicHUD Added");
				}
			}
		}
	}
	[HarmonyPatch(typeof(HUDManager))]
	public class HudPatches
	{
		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void Awake_Postfix(HUDManager __instance)
		{
			//IL_005d: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Expected O, but got Unknown
			Instruments4MusicPlugin.HudManager = __instance;
			HUDElement[] privateField = __instance.GetPrivateField<HUDElement[]>("HUDElements");
			GameObject val = (Instruments4MusicPlugin.HudInstance = Object.Instantiate<GameObject>(Instruments4MusicPlugin.HudPrefab, ((Component)privateField[0].canvasGroup).transform.parent));
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Transform transform = val.transform;
			Vector3 val2 = new Vector3(1f, 1f, 1f);
			ConfigEntry<float>? configHudScale = InstrumentsConfig.ConfigHudScale;
			float num;
			if (configHudScale != null)
			{
				_ = configHudScale.Value;
				if (true)
				{
					num = InstrumentsConfig.ConfigHudScale.Value;
					goto IL_0088;
				}
			}
			num = 1f;
			goto IL_0088;
			IL_0088:
			transform.localScale = val2 * num;
			Instruments4MusicPlugin.AddLog("MusicHUD Instantiated");
			HUDElement val3 = (Instruments4MusicPlugin.HudElement = new HUDElement());
			CanvasGroup canvasGroup = val.GetComponent<CanvasGroup>() ?? val.AddComponent<CanvasGroup>();
			val3.canvasGroup = canvasGroup;
			__instance.PingHUDElement(val3, 0f, 0f, 0f);
			HUDElement[] array = privateField;
			List<HUDElement> list = new List<HUDElement>(1 + array.Length);
			HUDElement[] array2 = array;
			foreach (HUDElement item in array2)
			{
				list.Add(item);
			}
			list.Add(val3);
			List<HUDElement> list2 = list;
			List<HUDElement> list3 = list2;
			int num2 = 0;
			HUDElement[] array3 = (HUDElement[])(object)new HUDElement[list3.Count];
			foreach (HUDElement item2 in list3)
			{
				array3[num2] = item2;
				num2++;
			}
			privateField = array3;
			((object)__instance).GetType().GetField("HUDElements", BindingFlags.Instance | BindingFlags.NonPublic)?.SetValue(__instance, privateField);
		}
	}
	public class InstrumentsConfig
	{
		internal static ConfigEntry<float>? ConfigHudScale;

		internal static ConfigEntry<float>? ConfigHudTransparency;

		internal static ConfigEntry<float>? TuneLastTime;

		internal static ConfigEntry<float>? VolumeAttenuationCoeff;

		internal static ConfigEntry<float>? SoftTuneModifier;

		internal static ConfigEntry<float>? SustainTuneModifier;

		internal static ConfigEntry<int>? AlarmHornBasePitch;

		internal static ConfigEntry<bool>? AlarmHornLoop;

		internal static ConfigEntry<int>? NoisyPropPitch;

		internal static ConfigEntry<bool>? NoisyPropLoop;

		internal static ConfigEntry<int>? StationaryPitch;

		internal static ConfigEntry<bool>? StationaryLoop;

		internal static ConfigEntry<int>? StationaryAudio;

		internal static ConfigEntry<int>? PotablePitch;

		internal static ConfigEntry<bool>? PotableLoop;

		internal static ConfigEntry<int>? PotableAudio;

		public static void Load()
		{
			ConfigFile? config = Instruments4MusicPlugin.config;
			ConfigHudScale = ((config != null) ? config.Bind<float>("HUDConfig", "HUDScale", 0.45f, "Scale the music HUD.") : null);
			ConfigFile? config2 = Instruments4MusicPlugin.config;
			ConfigHudTransparency = ((config2 != null) ? config2.Bind<float>("HUDConfig", "HUDTransparency", 1f, "Transparency of the music HUD.") : null);
			ConfigFile? config3 = Instruments4MusicPlugin.config;
			TuneLastTime = ((config3 != null) ? config3.Bind<float>("TuneModifiers", "TuneLastTime", 3f, "The audio will stop playing at TuneLastTime.(unit: seconds)") : null);
			ConfigFile? config4 = Instruments4MusicPlugin.config;
			VolumeAttenuationCoeff = ((config4 != null) ? config4.Bind<float>("TuneModifiers", "VolumeAttenuationCoeff", 2f, "Volume = exp(-alpha * t), alpha is this coefficient, t is time.") : null);
			ConfigFile? config5 = Instruments4MusicPlugin.config;
			SoftTuneModifier = ((config5 != null) ? config5.Bind<float>("TuneModifiers", "SoftTuneModifier", 0.5f, "When you hit the soft pedal. Volume = Volume * SoftModifier") : null);
			ConfigFile? config6 = Instruments4MusicPlugin.config;
			SustainTuneModifier = ((config6 != null) ? config6.Bind<float>("TuneModifiers", "SustainTuneModifier", 4f, "When you hit the sustain pedal. TuneLastTime = TuneLastTime * SustainModifier, and the Volume also attenuate slower.") : null);
			ConfigFile? config7 = Instruments4MusicPlugin.config;
			AlarmHornBasePitch = ((config7 != null) ? config7.Bind<int>("AlarmHornConfig", "AlarmHornBasePitch", 8, "The default audio \"ShipAlarmHornConstant.ogg\" is approximately C1#\n[0, 35] refers to [Low C, High B]") : null);
			ConfigFile? config8 = Instruments4MusicPlugin.config;
			AlarmHornLoop = ((config8 != null) ? config8.Bind<bool>("AlarmHornConfig", "AlarmHornLoop", true, "Playback the audio repeatedly until you stop pressing.") : null);
			ConfigFile? config9 = Instruments4MusicPlugin.config;
			NoisyPropPitch = ((config9 != null) ? config9.Bind<int>("NoisyPropDefault", "NoisyPropPitch", 12, "For activable props like Air Horn or Clown Horn.\n12 means Mid C.\n[0, 35] refers to [Low C, High B]") : null);
			ConfigFile? config10 = Instruments4MusicPlugin.config;
			NoisyPropLoop = ((config10 != null) ? config10.Bind<bool>("NoisyPropDefault", "NoisyPropLoop", false, "For activable props like Air Horn or Clown Horn.\nPlayback the audio repeatedly until you stop pressing.") : null);
			ConfigFile? config11 = Instruments4MusicPlugin.config;
			StationaryPitch = ((config11 != null) ? config11.Bind<int>("StationaryDefault", "StationaryPitch", 12, "12 means Mid C.\n[0, 35] refers to [Low C, High B]") : null);
			ConfigFile? config12 = Instruments4MusicPlugin.config;
			StationaryLoop = ((config12 != null) ? config12.Bind<bool>("StationaryDefault", "StationaryLoop", false, "Playback the audio repeatedly until you stop pressing.") : null);
			ConfigFile? config13 = Instruments4MusicPlugin.config;
			StationaryAudio = ((config13 != null) ? config13.Bind<int>("StationaryDefault", "StationaryAudio", 0, "I'm not quite sure what these audio means, but anyway it's configurable.\n0-thisAudioSourceClip, 1-playWhileTrue, 2-boolTrueAudios, 3-boolFalseAudios, 4-secondaryAudios.") : null);
			ConfigFile? config14 = Instruments4MusicPlugin.config;
			PotablePitch = ((config14 != null) ? config14.Bind<int>("PotableDefault", "PotablePitch", 12, "12 means Mid C.\n[0, 35] refers to [Low C, High B]") : null);
			ConfigFile? config15 = Instruments4MusicPlugin.config;
			PotableLoop = ((config15 != null) ? config15.Bind<bool>("PotableDefault", "PotableLoop", false, "Playback the audio repeatedly until you stop pressing.") : null);
			ConfigFile? config16 = Instruments4MusicPlugin.config;
			PotableAudio = ((config16 != null) ? config16.Bind<int>("PotableDefault", "PotableAudio", 0, "I think I know what these audio means literally.\n0-dropSFX, 1-grabSFX, 2-pocketSFX, 3-throwSFX.") : null);
			Instruments4MusicPlugin.AddLog("All configs loaded!");
		}
	}
	public class MusicHud : MonoBehaviour
	{
		public static MusicHud? Instance;

		private readonly List<Image> _frameRectangles = new List<Image>();

		private readonly List<Image> _textRectangles = new List<Image>();

		private static readonly List<Text> ButtonTips = new List<Text>();

		private static readonly List<Image> MenuRectangles = new List<Image>();

		private static readonly List<Text> MenuTips = new List<Text>();

		private InputField inputField;

		public bool IsInputing = false;

		public Dictionary<int, IEnumerator> CurrentCoroutines = new Dictionary<int, IEnumerator>();

		private readonly Dictionary<int, bool> _rotateFinished = new Dictionary<int, bool>();

		private void Awake()
		{
			if ((Object)(object)Instance != (Object)null)
			{
				throw new Exception("More than one instance of UI!");
			}
			Instance = this;
		}

		private void Start()
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_015f: 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_0184: Expected O, but got Unknown
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: 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_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Expected O, but got Unknown
			//IL_0298: 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_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: 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_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Expected O, but got Unknown
			//IL_03bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0440: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_045b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_0482: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Expected O, but got Unknown
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0520: Unknown result type (might be due to invalid IL or missing references)
			//IL_0537: Unknown result type (might be due to invalid IL or missing references)
			//IL_054e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0565: Unknown result type (might be due to invalid IL or missing references)
			//IL_0597: Unknown result type (might be due to invalid IL or missing references)
			//IL_059e: Expected O, but got Unknown
			//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_060f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0626: Unknown result type (might be due to invalid IL or missing references)
			//IL_063d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0656: Unknown result type (might be due to invalid IL or missing references)
			//IL_065b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0665: Unknown result type (might be due to invalid IL or missing references)
			//IL_0682: Unknown result type (might be due to invalid IL or missing references)
			//IL_0689: Expected O, but got Unknown
			//IL_06ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0703: Unknown result type (might be due to invalid IL or missing references)
			//IL_071a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0731: Unknown result type (might be due to invalid IL or missing references)
			float num = ((InstrumentsConfig.ConfigHudTransparency == null) ? 1f : InstrumentsConfig.ConfigHudTransparency.Value);
			GameObject hudInstance = Instruments4MusicPlugin.HudInstance;
			Button[] componentsInChildren = hudInstance.GetComponentsInChildren<Button>();
			Image[] itemSlotIconFrames = Instruments4MusicPlugin.HudManager.itemSlotIconFrames;
			Instruments4MusicPlugin.AddLog("Draw MusicHUD");
			_frameRectangles.Clear();
			_textRectangles.Clear();
			ButtonTips.Clear();
			MenuRectangles.Clear();
			MenuTips.Clear();
			Button[] array = componentsInChildren;
			Rect rect;
			foreach (Button val in array)
			{
				RectTransform component = ((Component)val).GetComponent<RectTransform>();
				int num2 = Random.Range(0, itemSlotIconFrames.Length);
				Image val2 = itemSlotIconFrames[num2];
				GameObject val3 = new GameObject("FrameRectangle");
				val3.transform.SetParent(((Component)val).transform, false);
				Image val4 = val3.AddComponent<Image>();
				((Graphic)val4).color = Color32.op_Implicit(new Color32((byte)254, (byte)73, (byte)0, (byte)Math.Round(num * 255f)));
				val4.sprite = val2.sprite;
				RectTransform component2 = val3.GetComponent<RectTransform>();
				component2.anchorMin = new Vector2(0f, 0f);
				component2.anchorMax = new Vector2(1f, 1f);
				component2.sizeDelta = new Vector2(0f, 0f);
				component2.anchoredPosition = new Vector2(0f, 0f);
				_frameRectangles.Add(val4);
				GameObject val5 = new GameObject("TextRectangle");
				val5.transform.SetParent(((Component)val).transform, false);
				Image val6 = val5.AddComponent<Image>();
				((Graphic)val6).color = Color32.op_Implicit(new Color32((byte)254, (byte)73, (byte)0, (byte)Math.Round(num * 255f)));
				RectTransform component3 = val5.GetComponent<RectTransform>();
				component3.anchorMin = new Vector2(0.3f, 0.3f);
				component3.anchorMax = new Vector2(0.7f, 0.7f);
				component3.offsetMin = new Vector2(0f, 0f);
				component3.offsetMax = new Vector2(0f, 0f);
				rect = component.rect;
				component3.anchoredPosition = new Vector2(0f, -0.5f * ((Rect)(ref rect)).height);
				_textRectangles.Add(val6);
				GameObject val7 = new GameObject("ButtonTip");
				val7.transform.SetParent(val5.transform, false);
				Text val8 = val7.AddComponent<Text>();
				rect = component3.rect;
				val8.fontSize = (int)(0.8f * ((Rect)(ref rect)).height);
				val8.text = "A";
				((Graphic)val8).color = Color.white;
				val8.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
				val8.alignment = (TextAnchor)4;
				val8.fontStyle = (FontStyle)1;
				RectTransform component4 = val7.GetComponent<RectTransform>();
				component4.anchorMin = new Vector2(0f, 0f);
				component4.anchorMax = new Vector2(1f, 1f);
				component4.sizeDelta = new Vector2(0f, 0f);
				component4.anchoredPosition = new Vector2(0f, 0f);
				ButtonTips.Add(val8);
			}
			RectTransform component5 = hudInstance.GetComponent<RectTransform>();
			for (int j = 0; j < 5; j++)
			{
				GameObject val9 = new GameObject("MenuRectangle");
				val9.transform.SetParent(hudInstance.transform, false);
				Image val10 = val9.AddComponent<Image>();
				((Graphic)val10).color = Color32.op_Implicit(new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, (byte)0));
				RectTransform component6 = val9.GetComponent<RectTransform>();
				component6.anchorMin = new Vector2(0.41f, 0.46f);
				component6.anchorMax = new Vector2(0.59f, 0.54f);
				component6.offsetMin = new Vector2(0f, 0f);
				component6.offsetMax = new Vector2(0f, 0f);
				float num3 = (float)(j - 2) * 0.2f;
				rect = component5.rect;
				float num4 = num3 * ((Rect)(ref rect)).width;
				rect = component5.rect;
				component6.anchoredPosition = new Vector2(num4, -0.4f * ((Rect)(ref rect)).height);
				MenuRectangles.Add(val10);
				GameObject val11 = new GameObject("MenuTip");
				val11.transform.SetParent(val9.transform, false);
				Text val12 = val11.AddComponent<Text>();
				rect = component5.rect;
				val12.fontSize = (int)(0.04f * ((Rect)(ref rect)).height);
				val12.text = "Text";
				((Graphic)val12).color = new Color(1f, 1f, 1f, num);
				val12.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
				val12.alignment = (TextAnchor)4;
				RectTransform component7 = val11.GetComponent<RectTransform>();
				component7.anchorMin = new Vector2(0f, 0f);
				component7.anchorMax = new Vector2(1f, 1f);
				component7.sizeDelta = new Vector2(0f, 0f);
				component7.anchoredPosition = new Vector2(0f, 0f);
				MenuTips.Add(val12);
			}
			GameObject val13 = new GameObject("InputField");
			val13.transform.SetParent(hudInstance.transform, false);
			Image val14 = val13.AddComponent<Image>();
			((Graphic)val14).color = Color32.op_Implicit(new Color32((byte)254, (byte)73, (byte)0, (byte)Math.Round(num * 255f)));
			RectTransform component8 = val13.GetComponent<RectTransform>();
			component8.anchorMin = new Vector2(0.2f, 0.46f);
			component8.anchorMax = new Vector2(0.8f, 0.54f);
			component8.offsetMin = new Vector2(0f, 0f);
			component8.offsetMax = new Vector2(0f, 0f);
			rect = component5.rect;
			component8.anchoredPosition = new Vector2(0f, 0.4f * ((Rect)(ref rect)).height);
			inputField = val13.AddComponent<InputField>();
			GameObject val15 = new GameObject("InputText");
			val15.transform.SetParent(val13.transform, false);
			Text val16 = val15.AddComponent<Text>();
			inputField.text = "Press Enter to input music note...";
			((Graphic)val16).color = Color.white;
			val16.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
			RectTransform component9 = val15.GetComponent<RectTransform>();
			component9.anchorMin = new Vector2(0f, 0f);
			component9.anchorMax = new Vector2(1f, 1f);
			component9.offsetMin = new Vector2(10f, 10f);
			component9.offsetMax = new Vector2(-10f, -10f);
			inputField.textComponent = val16;
			Instruments4MusicPlugin.AddLog("Draw MusicHUD success");
		}

		public static void ShowUserInterface()
		{
			float value = InstrumentsConfig.ConfigHudTransparency.Value;
			UpdateButtonTips();
			MenuTips[0].text = "Quit: " + InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.CurtainCall);
			MenuTips[1].text = "Soft: " + InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.Soft);
			MenuTips[2].text = "Semi: " + InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.Semitone);
			MenuTips[3].text = "Sustain: " + InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.Sustain);
			MenuTips[4].text = "Switch: " + InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.ChangeMode);
			HUDManager? hudManager = Instruments4MusicPlugin.HudManager;
			if (hudManager != null)
			{
				hudManager.PingHUDElement(Instruments4MusicPlugin.HudElement, 0f, 0f, value);
			}
		}

		public static void UpdateButtonTips()
		{
			Instruments4MusicPlugin.AddLog("Load key binds");
			string[] array = (TuneAudioScript.SecondaryKeyBind ? new string[21]
			{
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowCKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowDKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowEKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowFKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowGKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowAKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowBKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidCKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidDKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidEKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidFKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidGKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidAKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidBKey2),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.HighCKey2),
				"",
				"",
				"",
				"",
				"",
				""
			} : new string[21]
			{
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowCKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowDKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowEKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowFKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowGKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowAKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.LowBKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidCKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidDKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidEKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidFKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidGKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidAKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.MidBKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.HighCKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.HighDKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.HighEKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.HighFKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.HighGKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.HighAKey),
				InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.HighBKey)
			});
			for (int i = 0; i < array.Length; i++)
			{
				ButtonTips[i].text = array[i];
			}
			Instruments4MusicPlugin.AddLog("Load key binds success");
		}

		public static void HideUserInterface()
		{
			HUDManager? hudManager = Instruments4MusicPlugin.HudManager;
			if (hudManager != null)
			{
				hudManager.PingHUDElement(Instruments4MusicPlugin.HudElement, 0f, 1f, 0f);
			}
		}

		private IEnumerator RotateOverTime(int noteNumber, RectTransform rectTransform)
		{
			Image textImage = _textRectangles[noteNumber];
			Color textImageColor = ((Graphic)textImage).color;
			textImageColor.a = 1f;
			((Graphic)textImage).color = textImageColor;
			Quaternion rotation;
			while (true)
			{
				rotation = ((Transform)rectTransform).rotation;
				if (!(((Quaternion)(ref rotation)).eulerAngles.y < 180f))
				{
					break;
				}
				float step = 360f * Time.deltaTime;
				rotation = ((Transform)rectTransform).rotation;
				float newAngle = Mathf.Min(((Quaternion)(ref rotation)).eulerAngles.y + step, 180f);
				((Transform)rectTransform).rotation = Quaternion.Euler(((Transform)rectTransform).eulerAngles.x, newAngle, ((Transform)rectTransform).eulerAngles.z);
				yield return null;
			}
			textImageColor.a = 0.5f;
			((Graphic)textImage).color = textImageColor;
			_rotateFinished[noteNumber] = true;
			while (true)
			{
				rotation = ((Transform)rectTransform).rotation;
				if (((Quaternion)(ref rotation)).eulerAngles.y > 0f)
				{
					float step2 = 360f * Time.deltaTime;
					rotation = ((Transform)rectTransform).rotation;
					float newAngle2 = Mathf.Max(((Quaternion)(ref rotation)).eulerAngles.y - step2, 0f);
					((Transform)rectTransform).rotation = Quaternion.Euler(((Transform)rectTransform).eulerAngles.x, newAngle2, ((Transform)rectTransform).eulerAngles.z);
					yield return null;
					continue;
				}
				break;
			}
		}

		public void OnButtonClicked(int num)
		{
			int num2 = NoteNumberConvert(num);
			if (!_rotateFinished.ContainsKey(num2) || _rotateFinished[num2])
			{
				if (CurrentCoroutines.TryGetValue(num2, out IEnumerator value))
				{
					((MonoBehaviour)this).StopCoroutine(value);
				}
				_rotateFinished[num2] = false;
				CurrentCoroutines[num2] = RotateOverTime(num2, ((Graphic)_frameRectangles[num2]).rectTransform);
				((MonoBehaviour)this).StartCoroutine(CurrentCoroutines[num2]);
			}
		}

		public void OnMenuClicked(int num, bool isHolding)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			float num2 = (isHolding ? 1f : 0f);
			Color32 val = Color32.op_Implicit(((Graphic)MenuRectangles[num]).color);
			val.a = (byte)(num2 * 255f);
			((Graphic)MenuRectangles[num]).color = Color32.op_Implicit(val);
		}

		private static int NoteNumberConvert(int num)
		{
			int[] array = new int[12]
			{
				0, 0, 1, 1, 2, 3, 3, 4, 4, 5,
				5, 6
			};
			return num / 12 * 7 + array[num % 12];
		}

		public void TriggerInputNote()
		{
			if (IsInputing)
			{
				inputField.DeactivateInputField();
				IsInputing = false;
				Instruments4MusicPlugin.AddLog("Input stop, get note: " + inputField.text + ".");
				TuneAudioScript.InitAutoPlay(inputField.text);
			}
			else
			{
				Instruments4MusicPlugin.AddLog("Input start.");
				inputField.ActivateInputField();
				IsInputing = true;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.bean.Instruments4Music";

		public const string PLUGIN_NAME = "Instruments4Music";

		public const string PLUGIN_VERSION = "2.1.0";
	}
	public class PortableScript : NetworkBehaviour
	{
		private const int InteractableObjectsMask = 512;

		private static PlayerControllerB? Player => GameNetworkManager.Instance?.localPlayerController;

		public static bool IsHoldingInstrument(out GameObject? instrumentObj)
		{
			if ((Object)(object)Player != (Object)null)
			{
				PlayerControllerB player = Player;
				if (((player != null && ((NetworkBehaviour)player).IsOwner && player.isPlayerControlled && (!((NetworkBehaviour)Player).IsServer || Player.isHostPlayerObject)) || Player.isTestingPlayer) && Player.isHoldingObject && !((Object)(object)Player.currentlyHeldObjectServer == (Object)null) && !Player.quickMenuManager.isMenuOpen && !Player.isPlayerDead)
				{
					if (!Player.currentlyHeldObjectServer.itemProperties.usableInSpecialAnimations)
					{
						player = Player;
						if (player == null || player.isGrabbingObjectAnimation || player.inTerminalMenu || player.isTypingChat || (Player.inSpecialInteractAnimation && !Player.inShockingMinigame))
						{
							goto IL_00f1;
						}
					}
					PlayerControllerB? player2 = Player;
					object obj;
					if (player2 == null)
					{
						obj = null;
					}
					else
					{
						GrabbableObject currentlyHeldObjectServer = player2.currentlyHeldObjectServer;
						obj = ((currentlyHeldObjectServer != null) ? ((Component)currentlyHeldObjectServer).gameObject : null);
					}
					instrumentObj = (GameObject?)obj;
					return (Object)(object)instrumentObj != (Object)null;
				}
			}
			goto IL_00f1;
			IL_00f1:
			instrumentObj = null;
			return false;
		}

		[ServerRpc(RequireOwnership = false)]
		public void LetShowBeginsServerRpc(ulong playerId, ulong objectId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1403104735u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, playerId);
					BytePacker.WriteValueBitPacked(val2, objectId);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1403104735u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					Instruments4MusicPlugin.AddLog($"LetShowBeginsServerRpc, owner: {((NetworkBehaviour)this).OwnerClientId}");
					LetShowBeginsClientRpc(playerId, objectId);
				}
			}
		}

		[ClientRpc]
		public void LetShowBeginsClientRpc(ulong playerId, ulong objectId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(758432294u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, playerId);
				BytePacker.WriteValueBitPacked(val2, objectId);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 758432294u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(objectId, out var value);
			GameObject gameObject = ((Component)value).gameObject;
			NoisemakerProp component = gameObject.GetComponent<NoisemakerProp>();
			if ((Object)(object)component != (Object)null && InstrumentsConfig.NoisyPropPitch != null && InstrumentsConfig.NoisyPropLoop != null)
			{
				Instruments4MusicPlugin.AddLog("Playing " + ((Object)component).name);
				AudioClip val3 = null;
				if ((Object)(object)component.noiseAudio.clip != (Object)null)
				{
					val3 = component.noiseAudio.clip;
				}
				else if (component.noiseSFX.Length != 0)
				{
					val3 = component.noiseSFX[0];
				}
				if ((Object)(object)val3 != (Object)null)
				{
					TuneAudioScript.RegisterInstrClip(playerId, gameObject, InstrumentsConfig.NoisyPropPitch.Value, val3, InstrumentsConfig.NoisyPropLoop.Value);
					return;
				}
			}
			if (InstrumentsConfig.PotablePitch == null || InstrumentsConfig.PotableLoop == null)
			{
				return;
			}
			WhoopieCushionItem component2 = gameObject.GetComponent<WhoopieCushionItem>();
			if ((Object)(object)component2 != (Object)null)
			{
				Instruments4MusicPlugin.AddLog("Playing " + ((Object)component2).name);
				TuneAudioScript.RegisterInstrClip(playerId, gameObject, InstrumentsConfig.PotablePitch.Value, component2.fartAudios[Random.Range(0, component2.fartAudios.Length)], InstrumentsConfig.PotableLoop.Value);
				return;
			}
			GrabbableObject component3 = gameObject.GetComponent<GrabbableObject>();
			if (!((Object)(object)component3 != (Object)null))
			{
				return;
			}
			Instruments4MusicPlugin.AddLog("Playing " + ((Object)component3).name);
			AudioClip val4 = null;
			if (InstrumentsConfig.PotableAudio != null)
			{
				if (InstrumentsConfig.PotableAudio.Value == 0)
				{
					val4 = component3.itemProperties.dropSFX;
				}
				else if (InstrumentsConfig.PotableAudio.Value == 1)
				{
					val4 = component3.itemProperties.grabSFX;
				}
				else if (InstrumentsConfig.PotableAudio.Value == 2)
				{
					val4 = component3.itemProperties.pocketSFX;
				}
				else if (InstrumentsConfig.PotableAudio.Value == 3)
				{
					val4 = component3.itemProperties.throwSFX;
				}
			}
			if ((Object)(object)val4 != (Object)null)
			{
				TuneAudioScript.RegisterInstrClip(playerId, gameObject, InstrumentsConfig.PotablePitch.Value, val4, InstrumentsConfig.PotableLoop.Value);
				return;
			}
			if ((Object)(object)component3.itemProperties.dropSFX != (Object)null)
			{
				val4 = component3.itemProperties.dropSFX;
			}
			else if ((Object)(object)component3.itemProperties.grabSFX != (Object)null)
			{
				val4 = component3.itemProperties.grabSFX;
			}
			else if ((Object)(object)component3.itemProperties.pocketSFX != (Object)null)
			{
				val4 = component3.itemProperties.pocketSFX;
			}
			else if ((Object)(object)component3.itemProperties.throwSFX != (Object)null)
			{
				val4 = component3.itemProperties.throwSFX;
			}
			if ((Object)(object)val4 != (Object)null)
			{
				TuneAudioScript.RegisterInstrClip(playerId, gameObject, InstrumentsConfig.PotablePitch.Value, val4, InstrumentsConfig.PotableLoop.Value);
			}
		}

		public void Update()
		{
			if (!((Object)(object)Player == (Object)null) && !TuneAudioScript.TheShowIsOn && IsHoldingInstrument(out GameObject instrumentObj) && Instruments4MusicPlugin.InputActionsInstance.Showtime != null)
			{
				GrabbableObject val = ((instrumentObj != null) ? instrumentObj.GetComponent<GrabbableObject>() : null);
				if (!((Object)(object)val == (Object)null))
				{
					string text = "Showtime!: [" + InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.Showtime) + "] (Hold)";
					HUDManager.Instance.ChangeControlTipMultiple(CollectionExtensions.AddToArray<string>(val.itemProperties.toolTips, text), true, val.itemProperties);
				}
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_PortableScript()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1403104735u, new RpcReceiveHandler(__rpc_handler_1403104735));
			NetworkManager.__rpc_func_table.Add(758432294u, new RpcReceiveHandler(__rpc_handler_758432294));
		}

		private static void __rpc_handler_1403104735(NetworkBehaviour? target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong playerId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				ulong objectId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref objectId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((PortableScript)(object)target).LetShowBeginsServerRpc(playerId, objectId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_758432294(NetworkBehaviour? target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong playerId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				ulong objectId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref objectId);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((PortableScript)(object)target).LetShowBeginsClientRpc(playerId, objectId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string? __getTypeName()
		{
			return "PortableScript";
		}
	}
	internal static class ReflectionUtils
	{
		public static T GetPrivateField<T>(this object obj, string field)
		{
			return (T)obj.GetType().GetField(field, BindingFlags.Instance | BindingFlags.NonPublic).GetValue(obj);
		}
	}
	public class StationaryScript : NetworkBehaviour
	{
		private const int InteractableObjectsMask = 512;

		private static PlayerControllerB? Player => GameNetworkManager.Instance?.localPlayerController;

		public static bool IsLookingAtInstrument(out GameObject? instrumentObj)
		{
			//IL_002f: 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_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Player == (Object)null)
			{
				instrumentObj = null;
				return false;
			}
			Ray val = default(Ray);
			((Ray)(ref val))..ctor(((Component)Player.gameplayCamera).transform.position, ((Component)Player.gameplayCamera).transform.forward);
			if (Player.isTypingChat)
			{
				instrumentObj = null;
				return false;
			}
			RaycastHit val2 = default(RaycastHit);
			if (!Physics.Raycast(val, ref val2, Player.grabDistance, 512, (QueryTriggerInteraction)1) && !Physics.Raycast(((Component)Player.gameplayCamera).transform.position + Vector3.up * 5f, Vector3.down, ref val2, 5f, 512, (QueryTriggerInteraction)1))
			{
				instrumentObj = null;
				return false;
			}
			instrumentObj = ((Component)((RaycastHit)(ref val2)).collider).gameObject;
			if ((Object)(object)instrumentObj == (Object)null)
			{
				instrumentObj = null;
				return false;
			}
			ShipAlarmCord component = instrumentObj.GetComponent<ShipAlarmCord>();
			if ((Object)(object)component != (Object)null)
			{
				return true;
			}
			ItemCharger component2 = instrumentObj.GetComponent<ItemCharger>();
			if ((Object)(object)component2 != (Object)null)
			{
				return true;
			}
			AnimatedObjectTrigger component3 = instrumentObj.GetComponent<AnimatedObjectTrigger>();
			if ((Object)(object)component3 != (Object)null)
			{
				return true;
			}
			return false;
		}

		[ServerRpc(RequireOwnership = false)]
		public void LetShowBeginsServerRpc(ulong playerId, ulong objectId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(356583999u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, playerId);
					BytePacker.WriteValueBitPacked(val2, objectId);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 356583999u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					Instruments4MusicPlugin.AddLog($"LetShowBeginsServerRpc, owner: {((NetworkBehaviour)this).OwnerClientId}");
					LetShowBeginsClientRpc(playerId, objectId);
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void LetShowBeginsServerRpc(ulong playerId, ulong objId, string path)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2002104037u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, playerId);
				BytePacker.WriteValueBitPacked(val2, objId);
				bool flag = path != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(path, false);
				}
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2002104037u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				Instruments4MusicPlugin.AddLog($"LetShowBeginsServerRpc, owner: {((NetworkBehaviour)this).OwnerClientId}");
				LetShowBeginsClientRpc(playerId, objId, path);
			}
		}

		[ClientRpc]
		public void LetShowBeginsClientRpc(ulong playerId, ulong objId, string path)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(119991791u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, playerId);
				BytePacker.WriteValueBitPacked(val2, objId);
				bool flag = path != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(path, false);
				}
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 119991791u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				GameObject val3 = TuneAudioScript.FindGameObjectFromPath(objId, path);
				if ((Object)(object)val3 == (Object)null)
				{
					Instruments4MusicPlugin.AddLog("Cannot find instrumentObj.");
				}
				else
				{
					LetShowBegins(playerId, val3);
				}
			}
		}

		[ClientRpc]
		public void LetShowBeginsClientRpc(ulong playerId, ulong objectId)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3302296507u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, playerId);
				BytePacker.WriteValueBitPacked(val2, objectId);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3302296507u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(objectId, out var value);
				if ((Object)(object)value == (Object)null)
				{
					Instruments4MusicPlugin.AddLog("Cannot find instrumentObj.");
					return;
				}
				GameObject gameObject = ((Component)value).gameObject;
				LetShowBegins(playerId, gameObject);
			}
		}

		public void LetShowBegins(ulong playerId, GameObject instrumentObj)
		{
			ShipAlarmCord component = instrumentObj.GetComponent<ShipAlarmCord>();
			if ((Object)(object)component != (Object)null && InstrumentsConfig.AlarmHornBasePitch != null && InstrumentsConfig.AlarmHornLoop != null)
			{
				Instruments4MusicPlugin.AddLog("Playing " + ((Object)component).name);
				TuneAudioScript.RegisterInstrClip(playerId, instrumentObj, InstrumentsConfig.AlarmHornBasePitch.Value, component.hornClose.clip, InstrumentsConfig.AlarmHornLoop.Value);
			}
			else
			{
				if (InstrumentsConfig.StationaryPitch == null || InstrumentsConfig.StationaryLoop == null)
				{
					return;
				}
				ItemCharger component2 = instrumentObj.GetComponent<ItemCharger>();
				if ((Object)(object)component2 != (Object)null)
				{
					Instruments4MusicPlugin.AddLog("Playing " + ((Object)component2).name);
					TuneAudioScript.RegisterInstrClip(playerId, instrumentObj, InstrumentsConfig.StationaryPitch.Value, component2.zapAudio.clip, InstrumentsConfig.StationaryLoop.Value);
					return;
				}
				AnimatedObjectTrigger component3 = instrumentObj.GetComponent<AnimatedObjectTrigger>();
				if (!((Object)(object)component3 != (Object)null))
				{
					return;
				}
				Instruments4MusicPlugin.AddLog("Playing " + ((Object)component3).name);
				AudioClip val = null;
				if (InstrumentsConfig.StationaryAudio != null)
				{
					if (InstrumentsConfig.StationaryAudio.Value == 0)
					{
						val = component3.thisAudioSource.clip;
					}
					else if (InstrumentsConfig.StationaryAudio.Value == 1)
					{
						val = component3.playWhileTrue;
					}
					else if (InstrumentsConfig.StationaryAudio.Value == 2)
					{
						val = component3.boolTrueAudios[0];
					}
					else if (InstrumentsConfig.StationaryAudio.Value == 3)
					{
						val = component3.boolFalseAudios[0];
					}
					else if (InstrumentsConfig.StationaryAudio.Value == 4)
					{
						val = component3.secondaryAudios[0];
					}
				}
				if ((Object)(object)val != (Object)null)
				{
					TuneAudioScript.RegisterInstrClip(playerId, instrumentObj, InstrumentsConfig.StationaryPitch.Value, val, InstrumentsConfig.StationaryLoop.Value);
					return;
				}
				if ((Object)(object)component3.thisAudioSource.clip != (Object)null)
				{
					val = component3.thisAudioSource.clip;
				}
				else if ((Object)(object)component3.playWhileTrue != (Object)null)
				{
					val = component3.playWhileTrue;
				}
				else if (component3.boolTrueAudios.Length != 0)
				{
					val = component3.boolTrueAudios[0];
				}
				else if (component3.boolFalseAudios.Length != 0)
				{
					val = component3.boolFalseAudios[0];
				}
				else if (component3.secondaryAudios.Length != 0)
				{
					val = component3.secondaryAudios[0];
				}
				if ((Object)(object)val != (Object)null)
				{
					TuneAudioScript.RegisterInstrClip(playerId, instrumentObj, InstrumentsConfig.StationaryPitch.Value, val, InstrumentsConfig.StationaryLoop.Value);
				}
			}
		}

		public void Update()
		{
			if (TuneAudioScript.TheShowIsOn || !IsLookingAtInstrument(out GameObject instrumentObj) || (Object)(object)Player == (Object)null || Instruments4MusicPlugin.InputActionsInstance.Showtime == null)
			{
				return;
			}
			string text = "Showtime!: [" + InputActions.GetButtonDescription(Instruments4MusicPlugin.InputActionsInstance.Showtime) + "] (Hold)";
			InteractTrigger val = ((instrumentObj != null) ? instrumentObj.GetComponent<InteractTrigger>() : null);
			if (!((Object)(object)val == (Object)null) && !val.hoverTip.EndsWith(text))
			{
				val.hoverTip = val.hoverTip + "\n" + text;
				Regex regex = new Regex("Showtime!: \\[.*?] \\(Hold\\)$");
				if (regex.IsMatch(val.hoverTip))
				{
					val.hoverTip = regex.Replace(val.hoverTip, text);
				}
				else
				{
					val.hoverTip = val.hoverTip + "\n" + text;
				}
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_StationaryScript()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(356583999u, new RpcReceiveHandler(__rpc_handler_356583999));
			NetworkManager.__rpc_func_table.Add(2002104037u, new RpcReceiveHandler(__rpc_handler_2002104037));
			NetworkManager.__rpc_func_table.Add(119991791u, new RpcReceiveHandler(__rpc_handler_119991791));
			NetworkManager.__rpc_func_table.Add(3302296507u, new RpcReceiveHandler(__rpc_handler_3302296507));
		}

		private static void __rpc_handler_356583999(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong playerId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				ulong objectId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref objectId);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((StationaryScript)(object)target).LetShowBeginsServerRpc(playerId, objectId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2002104037(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong playerId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				ulong objId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref objId);
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string path = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref path, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((StationaryScript)(object)target).LetShowBeginsServerRpc(playerId, objId, path);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_119991791(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong playerId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				ulong objId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref objId);
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string path = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref path, false);
				}
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((StationaryScript)(object)target).LetShowBeginsClientRpc(playerId, objId, path);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3302296507(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				ulong playerId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref playerId);
				ulong objectId = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref objectId);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((StationaryScript)(object)target).LetShowBeginsClientRpc(playerId, objectId);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "StationaryScript";
		}
	}
	public class TuneAudioScript : NetworkBehaviour
	{
		private float timer = 0f;

		public float interval = 1f;

		private const double TuneCoeff = 1.0594631433486938;

		private static readonly float LastTimer;

		public static readonly float AttenuationCoeff;

		public static readonly float SoftModifier;

		private static readonly float SustainModifier;

		private static Dictionary<ulong, AudioClip> _instrClips;

		private static Dictionary<ulong, int> _sourceNoteNumber;

		private static Dictionary<ulong, bool> _loopAudio;

		private static Dictionary<ulong, Dictionary<int, AudioSource>> _tunedPlayerDictionary;

		private static Dictionary<ulong, ConcurrentDictionary<int, float>> _timerPlayerDictionary;

		private static readonly List<List<(int, bool, int)>> TuneList;

		private static readonly List<List<(int, bool, int)>> KeepTuneList;

		public static bool SecondaryTuneMethod;

		public static bool TheShowIsOn;

		public static bool SecondaryKeyBind;

		public static bool KeyBindInit;

		public static Dictionary<ulong, bool> IsSustaining;

		public static bool IsAutoPlayOn;

		public static float AutoPlaySpeed;

		public static float AutoPlayCount;

		public static Dictionary<ulong, GameObject> ActiveInstrObjects;

		private static PlayerControllerB? Player => GameNetworkManager.Instance?.localPlayerController;

		public static void RegisterInstrClip(ulong playerId, GameObject gameObject, int originNoteNumber, AudioClip clip, bool isLoop)
		{
			foreach (ConcurrentDictionary<int, float> value in _timerPlayerDictionary.Values)
			{
				value.Clear();
			}
			_timerPlayerDictionary.Clear();
			foreach (Dictionary<int, AudioSource> value2 in _tunedPlayerDictionary.Values)
			{
				foreach (AudioSource value3 in value2.Values)
				{
					if ((Object)(object)value3 != (Object)null)
					{
						value3.outputAudioMixerGroup = null;
						Object.Destroy((Object)(object)value3);
					}
				}
				value2.Clear();
			}
			_tunedPlayerDictionary.Clear();
			Instruments4MusicPlugin.AddLog("TunedDictionary cleared.");
			_instrClips[playerId] = clip;
			_sourceNoteNumber[playerId] = originNoteNumber;
			_loopAudio[playerId] = isLoop;
			ActiveInstrObjects[playerId] = gameObject;
			Instruments4MusicPlugin.AddLog("Playing " + ((Object)clip).name + ".");
		}

		public static void ActiveInstrument()
		{
			TheShowIsOn = true;
			MusicHud.ShowUserInterface();
			if ((Object)(object)MusicHud.Instance != (Object)null && MusicHud.Instance.IsInputing)
			{
				MusicHud.Instance.TriggerInputNote();
			}
			if (!SecondaryKeyBind)
			{
				DisableController();
			}
			Instruments4MusicPlugin.AddLog("Active Instrument.");
		}

		public static void DeActiveInstrument()
		{
			TheShowIsOn = false;
			EnableController();
			MusicHud.HideUserInterface();
			Instruments4MusicPlugin.AddLog("DeActive Instrument.");
		}

		[ServerRpc(RequireOwnership = false)]
		public void PlayTunedAudioServerRpc(ulong playerId, int targetNoteNumber, bool isSoft, bool newPulse, bool secondaryTuneMethod)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(3699046614u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, playerId);
					BytePacker.WriteValueBitPacked(val2, targetNoteNumber);
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref isSoft, default(ForPrimitives));
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref newPulse, default(ForPrimitives));
					((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref secondaryTuneMethod, default(ForPrimitives));
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 3699046614u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					PlayTunedAudioClientRpc(playerId, targetNoteNumber, isSoft, newPulse, secondaryTuneMethod);
				}
			}
		}

		[ClientRpc]
		public void PlayTunedAudioClientRpc(ulong playerId, int targetNoteNumber, bool isSoft, bool newPulse, bool secondaryTuneMethod)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(305110489u, val, (RpcDelivery)0);
				BytePacker.WriteValueBitPacked(val2, playerId);
				BytePacker.WriteValueBitPacked(val2, targetNoteNumber);
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref isSoft, default(ForPrimitives));
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref newPulse, default(ForPrimitives));
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref secondaryTuneMethod, default(ForPrimitives));
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 305110489u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage != 2 || (!networkManager.IsClient && !networkManager.IsHost))
			{
				return;
			}
			MusicHud.Instance?.OnButtonClicked(targetNoteNumber);
			if (!_timerPlayerDictionary.ContainsKey(playerId))
			{
				_timerPlayerDictionary[playerId] = new ConcurrentDictionary<int, float>();
			}
			_timerPlayerDictionary[playerId][targetNoteNumber] = LastTimer;
			float num = 1f;
			if (isSoft && newPulse)
			{
				num -= SoftModifier;
			}
			int num2 = targetNoteNumber - _sourceNoteNumber[playerId];
			if (_tunedPlayerDictionary.TryGetValue(playerId, out Dictionary<int, AudioSource> value) && value.TryGetValue(targetNoteNumber, out var value2))
			{
				value2.volume = num;
				if (!newPulse)
				{
					return;
				}
				if (secondaryTuneMethod)
				{
					if (num2 > 12)
					{
						value2.pitch = (float)Math.Pow(1.0594631433486938, num2 - 12);
					}
					else if (num2 < -12)
					{
						value2.pitch = (float)Math.Pow(1.0594631433486938, num2 + 12);
					}
					else
					{
						value2.pitch = 1f;
					}
					AudioSource obj = value2;
					AudioMixer? tuneMixer = Instruments4MusicPlugin.TuneMixer;
					obj.outputAudioMixerGroup = ((tuneMixer != null) ? tuneMixer.FindMatchingGroups($"Tune{Math.Max(-12, Math.Min(12, num2))}")[0] : null);
				}
				else
				{
					if (num2 > 12)
					{
						AudioSource obj2 = value2;
						AudioMixer? tuneMixer2 = Instruments4MusicPlugin.TuneMixer;
						obj2.outputAudioMixerGroup = ((tuneMixer2 != null) ? tuneMixer2.FindMatchingGroups($"Tune{num2 - 12}")[0] : null);
					}
					else if (num2 < -12)
					{
						AudioSource obj3 = value2;
						AudioMixer? tuneMixer3 = Instruments4MusicPlugin.TuneMixer;
						obj3.outputAudioMixerGroup = ((tuneMixer3 != null) ? tuneMixer3.FindMatchingGroups($"Tune{num2 + 12}")[0] : null);
					}
					else
					{
						value2.outputAudioMixerGroup = null;
					}
					value2.pitch = (float)Math.Pow(1.0594631433486938, Math.Max(-12, Math.Min(12, num2)));
				}
				value2.Play();
			}
			else
			{
				if (!ActiveInstrObjects.ContainsKey(playerId) || !_instrClips.ContainsKey(playerId))
				{
					return;
				}
				GameObject obj4 = ActiveInstrObjects[playerId];
				value2 = ((obj4 != null) ? obj4.AddComponent<AudioSource>() : null);
				if ((Object)(object)value2 == (Object)null)
				{
					return;
				}
				if (secondaryTuneMethod)
				{
					if (num2 > 12)
					{
						value2.pitch = (float)Math.Pow(1.0594631433486938, num2 - 12);
					}
					else if (num2 < -12)
					{
						value2.pitch = (float)Math.Pow(1.0594631433486938, num2 + 12);
					}
					else
					{
						value2.pitch = 1f;
					}
					AudioSource obj5 = value2;
					AudioMixer? tuneMixer4 = Instruments4MusicPlugin.TuneMixer;
					obj5.outputAudioMixerGroup = ((tuneMixer4 != null) ? tuneMixer4.FindMatchingGroups($"Tune{Math.Max(-12, Math.Min(12, num2))}")[0] : null);
				}
				else
				{
					if (num2 > 12)
					{
						AudioSource obj6 = value2;
						AudioMixer? tuneMixer5 = Instruments4MusicPlugin.TuneMixer;
						obj6.outputAudioMixerGroup = ((tuneMixer5 != null) ? tuneMixer5.FindMatchingGroups($"Tune{num2 - 12}")[0] : null);
					}
					else if (num2 < -12)
					{
						AudioSource obj7 = value2;
						AudioMixer? tuneMixer6 = Instruments4MusicPlugin.TuneMixer;
						obj7.outputAudioMixerGroup = ((tuneMixer6 != null) ? tuneMixer6.FindMatchingGroups($"Tune{num2 + 12}")[0] : null);
					}
					else
					{
						value2.outputAudioMixerGroup = null;
					}
					value2.pitch = (float)Math.Pow(1.0594631433486938, Math.Max(-12, Math.Min(12, num2)));
				}
				value2.clip = _instrClips[playerId];
				value2.volume = num;
				value2.loop = _loopAudio[playerId];
				value2.spatialBlend = 1f;
				value2.spread = 26f;
				value2.rolloffMode = (AudioRolloffMode)1;
				value2.minDistance = 4f;
				value2.maxDistance = 21f;
				if (!_tunedPlayerDictionary.ContainsKey(playerId))
				{
					_tunedPlayerDictionary[playerId] = new Dictionary<int, AudioSource>();
				}
				_tunedPlayerDictionary[playerId][targetNoteNumber] = value2;
				value2.Play();
			}
		}

		public static void InitAutoPlay(string musicNotes)
		{
			IsAutoPlayOn = false;
			if (!TheShowIsOn)
			{
				return;
			}
			int[] array = new int[7] { 9, 11, 0, 2, 4, 5, 7 };
			int[] array2 = new int[7] { 12, 14, 16, 17, 19, 21, 23 };
			int[] array3 = new int[7] { 33, 35, 24, 26, 28, 29, 31 };
			string[] array4 = Regex.Replace(musicNotes, "\\s+", "").Split(',');
			int num = 0;
			TuneList.Clear();
			if (array4.Length < 2 || !float.TryParse(array4[0], out AutoPlaySpeed))
			{
				return;
			}
			for (int i = 1; i < array4.Length; i++)
			{
				List<(int, bool, int)> list = new List<(int, bool, int)>();
				if (array4[i].Length % 2 != 1 || array4[i].Length < 2)
				{
					TuneList.Add(list);
					continue;
				}
				char c = array4[i][0];
				bool flag = !char.IsDigit(c);
				bool flag2 = flag;
				if (flag2)
				{
					bool flag3;
					switch (c)
					{
					default:
						flag3 = true;
						break;
					case 'A':
					case 'B':
					case 'C':
					case 'D':
					case 'E':
					case 'F':
					case 'a':
					case 'b':
					case 'c':
					case 'd':
					case 'e':
					case 'f':
						flag3 = false;
						break;
					}
					flag2 = flag3;
				}
				if (flag2)
				{
					TuneList.Add(list);
					continue;
				}
				int num2 = Convert.ToInt32(c.ToString(), 16);
				IsSustaining[((NetworkBehaviour)Instruments4MusicPlugin.Player).NetworkObjectId] = (num2 & 1) != 0;
				bool item = (num2 & 2) != 0;
				for (int j = 1; j < array4[i].Length; j += 2)
				{
					char c2 = array4[i][j];
					char c3 = c2;
					char c4 = c3;
					int num3;
					if (c4 >= 'A')
					{
						if (c4 >= 'a')
						{
							if (c4 > 'g')
							{
								continue;
							}
							num3 = array[c2 - 97];
						}
						else
						{
							if (c4 > 'G')
							{
								continue;
							}
							num3 = array3[c2 - 65];
						}
					}
					else
					{
						if (c4 < '1' || c4 > '7')
						{
							continue;
						}
						num3 = array2[c2 - 49];
					}
					char c5 = array4[i][j + 1];
					bool flag4 = !char.IsDigit(c5);
					bool flag5 = flag4;
					if (flag5)
					{
						bool flag3;
						switch (c5)
						{
						default:
							flag3 = true;
							break;
						case 'A':
						case 'B':
						case 'C':
						case 'D':
						case 'E':
						case 'F':
						case 'a':
						case 'b':
						case 'c':
						case 'd':
						case 'e':
						case 'f':
							flag3 = false;
							break;
						}
						flag5 = flag3;
					}
					if (!flag5)
					{
						num3 += ((c5 >= '8') ? 1 : 0);
						int num4 = Convert.ToInt32(c5.ToString(), 16) & 7;
						num = ((num4 > num) ? num4 : num);
						list.Add((num3, item, num4));
					}
				}
				TuneList.Add(list);
			}
			AutoPlayCount = 0f;
			KeepTuneList.Clear();
			for (int k = 0; k < TuneList.Count + num; k++)
			{
				KeepTuneList.Add(new List<(int, bool, int)>());
			}
			IsAutoPlayOn = true;
		}

		public void DoAutoPlay()
		{
			ulong networkObjectId = ((NetworkBehaviour)Instruments4MusicPlugin.Player).NetworkObjectId;
			if (!IsAutoPlayOn)
			{
				return;
			}
			AutoPlayCount += Time.deltaTime;
			int num = (int)(AutoPlayCount / 0.5f * AutoPlaySpeed);
			num -= 4;
			if (num < 0)
			{
				return;
			}
			if (num >= TuneList.Count)
			{
				IsAutoPlayOn = false;
				return;
			}
			foreach (var item in TuneList[num])
			{
				var (noteNumber2, flag, num2) = item;
				if (KeepTuneList[num].All(((int, bool, int) tup) => tup.Item1 != noteNumber2))
				{
					PlayTunedAudioServerRpc(networkObjectId, noteNumber2, flag, newPulse: true, SecondaryTuneMethod);
					KeepTuneList[num].Add((noteNumber2, flag, 0));
				}
				if (num2 > 0 && TuneList[num + 1].All(((int, bool, int) tup) => tup.Item1 != noteNumber2) && KeepTuneList[num + 1].All(((int, bool, int) tup) => tup.Item1 != noteNumber2))
				{
					KeepTuneList[num + 1].Add((noteNumber2, flag, num2 - 1));
				}
			}
			foreach (var item2 in KeepTuneList[num])
			{
				var (noteNumber, flag2, num3) = item2;
				PlayTunedAudioServerRpc(networkObjectId, noteNumber, flag2, newPulse: false, SecondaryTuneMethod);
				if (num3 > 0 && TuneList[num + 1].All(((int, bool, int) tup) => tup.Item1 != noteNumber) && KeepTuneList[num + 1].All(((int, bool, int) tup) => tup.Item1 != noteNumber))
				{
					KeepTuneList[num + 1].Add((noteNumber, flag2, num3 - 1));
				}
			}
		}

		public static void AudioCountDown()
		{
			foreach (ulong key in _timerPlayerDictionary.Keys)
			{
				foreach (int key2 in _timerPlayerDictionary[key].Keys)
				{
					float num = _timerPlayerDictionary[key][key2];
					if (_tunedPlayerDictionary[key].TryGetValue(key2, out AudioSource value) && num >= 0f && value.volume > 0.01f)
					{
						if (IsSustaining.ContainsKey(key) && IsSustaining[key])
						{
							_timerPlayerDictionary[key][key2] = num - Time.deltaTime / SustainModifier;
							value.volume = (float)((double)value.volume * Math.Exp((0f - AttenuationCoeff) * Time.deltaTime / SustainModifier));
						}
						else
						{
							_timerPlayerDictionary[key][key2] = num - Time.deltaTime;
							value.volume = (float)((double)value.volume * Math.Exp((0f - AttenuationCoeff) * Time.deltaTime));
						}
					}
					else
					{
						if (value != null)
						{
							value.Stop();
						}
						_timerPlayerDictionary[key].Remove(key2, out var _);
					}
				}
			}
		}

		private static void EnableController()
		{
			try
			{
				if (!((Object)(object)Player == (Object)null))
				{
					Player.inTerminalMenu = false;
					Player.inSpecialInteractAnimation = false;
					Object.FindObjectOfType<Terminal>().timeSinceTerminalInUse = 0f;
					Instruments4MusicPlugin.AddLog("Trying to re-enable the controller.");
				}
			}
			catch (Exception arg)
			{
				Debug.LogError((object)$"Error while subscribing to input in PlayerController!: {arg}");
			}
		}

		private static void DisableController()
		{
			try
			{
				if (!((Object)(object)Player == (Object)null))
				{
					Player.inTerminalMenu = true;
					Player.inSpecialInteractAnimation = true;
					Instruments4MusicPlugin.AddLog("Trying to disable the controller.");
				}
			}
			catch (Exception arg)
			{
				Debug.LogError((object)$"Error while unsubscribing from input in PlayerController!: {arg}");
			}
		}

		public void Awake()
		{
			_tunedPlayerDictionary = new Dictionary<ulong, Dictionary<int, AudioSource>>();
			_timerPlayerDictionary = new Dictionary<ulong, ConcurrentDictionary<int, float>>();
			SecondaryTuneMethod = false;
			TheShowIsOn = false;
			SecondaryKeyBind = false;
			if (!KeyBindInit)
			{
				SetupKeyBindCallbacks();
				KeyBindInit = true;
			}
		}

		public void SetupKeyBindCallbacks()
		{
			Instruments4MusicPlugin.InputActionsInstance.SwitchTuneMethod.performed += OnSwitchTuneMethodPressed;
			Instruments4MusicPlugin.InputActionsInstance.Showtime.performed += OnShowtimePressed;
			Instruments4MusicPlugin.InputActionsInstance.CurtainCall.performed += OnCurtainCallPressed;
			Instruments4MusicPlugin.InputActionsInstance.ChangeMode.performed += OnChangeModePressed;
			Instruments4MusicPlugin.InputActionsInstance.InputNote.performed += OnInputNotePressed;
		}

		public void OnSwitchTuneMethodPressed(CallbackContext switchTuneMethodContext)
		{
			if (TheShowIsOn && ((CallbackContext)(ref switchTuneMethodContext)).performed)
			{
				SecondaryTuneMethod = !SecondaryTuneMethod;
				Instruments4MusicPlugin.AddLog($"Switch Tune Secondary {SecondaryTuneMethod}.");
			}
		}

		public void OnShowtimePressed(CallbackContext showtimeContext)
		{
			if (TheShowIsOn || !((CallbackContext)(ref showtimeContext)).performed)
			{
				return;
			}
			if (StationaryScript.IsLookingAtInstrument(out GameObject instrumentObj))
			{
				if (!((Object)(object)instrumentObj == (Object)null))
				{
					Instruments4MusicPlugin.AddLog("Looking at Stationary");
					(ulong, string)? tuple = FindNearestNetworkObject(instrumentObj);
					if (tuple.HasValue)
					{
						ulong item = tuple.Value.Item1;
						string item2 = tuple.Value.Item2;
						Instruments4MusicPlugin.AddLog("Try begin");
						Instruments4MusicPlugin.Stationary.LetShowBeginsServerRpc(((NetworkBehaviour)Instruments4MusicPlugin.Player).NetworkObjectId, item, item2);
						ActiveInstrument();
					}
				}
			}
			else if (PortableScript.IsHoldingInstrument(out instrumentObj) && !((Object)(object)instrumentObj == (Object)null))
			{
				Instruments4MusicPlugin.AddLog("Looking at Portable");
				NetworkObject component = instrumentObj.GetComponent<NetworkObject>();
				if ((Object)(object)component != (Object)null)
				{
					Instruments4MusicPlugin.AddLog("Try begin");
					Instruments4MusicPlugin.Portable.LetShowBeginsServerRpc(((NetworkBehaviour)Instruments4MusicPlugin.Player).NetworkObjectId, component.NetworkObjectId);
					ActiveInstrument();
				}
			}
		}

		private static (ulong, string)? FindNearestNetworkObject(GameObject current)
		{
			List<int> list = new List<int>();
			NetworkObject val = null;
			Transform val2 = current.transform;
			while ((Object)(object)val2 != (Object)null)
			{
				val = ((Component)val2).GetComponent<NetworkObject>();
				if ((Object)(object)val != (Object)null)
				{
					break;
				}
				int siblingIndex = val2.GetSiblingIndex();
				list.Insert(0, siblingIndex);
				val2 = val2.parent;
			}
			if ((Object)(object)val == (Object)null)
			{
				Instruments4MusicPlugin.AddLog("NetworkObject not found.");
				return null;
			}
			return (val.NetworkObjectId, string.Concat(list.Select((int i) => (char)(i + 65))));
		}

		public static GameObject? FindGameObjectFromPath(ulong objId, string pathSTR)
		{
			NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(objId, out var value);
			Transform val = ((Component)value).transform;
			List<int> list = new List<int>();
			foreach (char c in pathSTR)
			{
				int item = c - 65;
				list.Add(item);
			}
			foreach (int item2 in list)
			{
				if (item2 < 0 || item2 >= val.childCount)
				{
					Instruments4MusicPlugin.AddLog("GameObject not found.");
					return null;
				}
				val = val.GetChild(item2);
			}
			return ((Component)val).gameObject;
		}

		public void OnCurtainCallPressed(CallbackContext curtainCallContext)
		{
			if (TheShowIsOn && ((CallbackContext)(ref curtainCallContext)).performed)
			{
				Instruments4MusicPlugin.AddLog("Maybe next time.");
				DeActiveInstrument();
			}
		}

		public void OnChangeModePressed(CallbackContext changeModeContext)
		{
			if (TheShowIsOn && ((CallbackContext)(ref changeModeContext)).performed)
			{
				Instruments4MusicPlugin.AddLog("Change key bind mode.");
				SecondaryKeyBind = !SecondaryKeyBind;
				if (SecondaryKeyBind)
				{
					EnableController();
				}
				else
				{
					DisableController();
				}
				MusicHud.UpdateButtonTips();
			}
		}

		public void OnInputNotePressed(CallbackContext inputNoteContext)
		{
			if (TheShowIsOn && ((CallbackContext)(ref inputNoteContext)).performed)
			{
				Instruments4MusicPlugin.AddLog("Input music note.");
				MusicHud.Instance.TriggerInputNote();
			}
		}

		public void Update()
		{
			ulong networkObjectId = ((NetworkBehaviour)Instruments4MusicPlugin.Player).NetworkObjectId;
			if (_timerPlayerDictionary.ContainsKey(networkObjectId) && _timerPlayerDictionary[networkObjectId].Count > 0)
			{
				if (!IsAutoPlayOn)
				{
					IsSustaining[networkObjectId] = Instruments4MusicPlugin.InputActionsInstance.Sustain.ReadValue<float>() > 0.5f;
				}
				AudioCountDown();
			}
			if (!TheShowIsOn)
			{
				return;
			}
			if (IsAutoPlayOn)
			{
				DoAutoPlay();
			}
			int num = 0;
			InputAction? soft = Instruments4MusicPlugin.InputActionsInstance.Soft;
			bool flag = soft != null && soft.ReadValue<float>() > 0.5f;
			InputAction? semitone = Instruments4MusicPlugin.InputActionsInstance.Semitone;
			if (semitone != null && semitone.ReadValue<float>() > 0.5f && !SecondaryKeyBind)
			{
				num = 1;
			}
			if (SecondaryKeyBind)
			{
				InputAction lowCKey = Instruments4MusicPlugin.InputActionsInstance.LowCKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTunedAudioServerRpc(networkObjectId, num, flag, lowCKey.triggered, SecondaryTuneMethod);
				}
				lowCKey = Instruments4MusicPlugin.InputActionsInstance.LowDKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTunedAudioServerRpc(networkObjectId, 2 + num, flag, lowCKey.triggered, SecondaryTuneMethod);
				}
				lowCKey = Instruments4MusicPlugin.InputActionsInstance.LowEKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTunedAudioServerRpc(networkObjectId, 4, flag, lowCKey.triggered, SecondaryTuneMethod);
				}
				lowCKey = Instruments4MusicPlugin.InputActionsInstance.LowFKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTunedAudioServerRpc(networkObjectId, 5 + num, flag, lowCKey.triggered, SecondaryTuneMethod);
				}
				lowCKey = Instruments4MusicPlugin.InputActionsInstance.LowGKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTunedAudioServerRpc(networkObjectId, 7 + num, flag, lowCKey.triggered, SecondaryTuneMethod);
				}
				lowCKey = Instruments4MusicPlugin.InputActionsInstance.LowAKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTunedAudioServerRpc(networkObjectId, 9 + num, flag, lowCKey.triggered, SecondaryTuneMethod);
				}
				lowCKey = Instruments4MusicPlugin.InputActionsInstance.LowBKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTunedAudioServerRpc(networkObjectId, 11, flag, lowCKey.triggered, SecondaryTuneMethod);
				}
				lowCKey = Instruments4MusicPlugin.InputActionsInstance.MidCKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTunedAudioServerRpc(networkObjectId, 12 + num, flag, lowCKey.triggered, SecondaryTuneMethod);
				}
				lowCKey = Instruments4MusicPlugin.InputActionsInstance.MidDKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTunedAudioServerRpc(networkObjectId, 14 + num, flag, lowCKey.triggered, SecondaryTuneMethod);
				}
				lowCKey = Instruments4MusicPlugin.InputActionsInstance.MidEKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTunedAudioServerRpc(networkObjectId, 16, flag, lowCKey.triggered, SecondaryTuneMethod);
				}
				lowCKey = Instruments4MusicPlugin.InputActionsInstance.MidFKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTunedAudioServerRpc(networkObjectId, 17 + num, flag, lowCKey.triggered, SecondaryTuneMethod);
				}
				lowCKey = Instruments4MusicPlugin.InputActionsInstance.MidGKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTunedAudioServerRpc(networkObjectId, 19 + num, flag, lowCKey.triggered, SecondaryTuneMethod);
				}
				lowCKey = Instruments4MusicPlugin.InputActionsInstance.MidAKey2;
				if (lowCKey != null && (lowCKey.ReadValue<float>() > 0.5f || lowCKey.triggered))
				{
					PlayTun