Decompiled source of Sony Walkman WM22 Delta Pizza Mix v0.2.0

Sony_Walkman_WM22_Delta_Pizza_Mix.dll

Decompiled an hour ago
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using FistVR;
using HarmonyLib;
using OtherLoader;
using UnityEngine;

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
namespace deltapizza.Sony_Walkman_WM22_Delta_Pizza_Mix
{
	[BepInPlugin("deltapizza.Sony_Walkman_WM22_Delta_Pizza_Mix", "Sony_Walkman_WM22_Delta_Pizza_Mix", "0.2.0")]
	[BepInProcess("h3vr.exe")]
	[Description("Built with MeatKit")]
	[BepInDependency("h3vr.otherloader", "1.3.0")]
	public class Sony_Walkman_WM22_Delta_Pizza_MixPlugin : BaseUnityPlugin
	{
		private static readonly string BasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

		internal static ManualLogSource Logger;

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			LoadAssets();
		}

		private void LoadAssets()
		{
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "deltapizza.Sony_Walkman_WM22_Delta_Pizza_Mix");
			OtherLoader.RegisterDirectLoad(BasePath, "deltapizza.Sony_Walkman_WM22_Delta_Pizza_Mix", "", "", "deltawalkmantapes", "");
		}
	}
}
namespace theWNbotMods
{
	public class SonyWalkman : FVRPhysicalObject
	{
		private enum TapeMode
		{
			Normal,
			FastForward,
			Rewind
		}

		[Header("Audio System")]
		public AudioSource audioSource;

		public AudioSource sfxSource;

		public AudioClip insertSound;

		public AudioClip ejectSound;

		[Header("Tape Slot")]
		public Transform tapeSlot;

		public Transform tapeInsertPoint;

		public Transform ejectPoint;

		private Tape insertedTape;

		private int insertedTapeOriginalLayer = -1;

		[Header("Detector")]
		[Tooltip("指定用于检测磁带插入的 trigger Collider(通常是 tapeInsertPoint 上的 Collider)。不要把 Walkman 的握持检测 Collider 拖到这里。")]
		public Collider detectorCollider;

		[Header("Buttons")]
		public SonyWalkmanButton playButton;

		public SonyWalkmanButton stopButton;

		public SonyWalkmanButton ffButton;

		public SonyWalkmanButton rewButton;

		[Header("Button Sounds")]
		public AudioClip buttonClickSound;

		[Header("FF/REW Settings")]
		public float ffSpeed = 2f;

		public float rewSpeed = 2f;

		public AudioClip ffSound;

		public AudioClip rewSound;

		[Header("Lid Settings")]
		public Transform lidTransform;

		public Vector3 lidClosedEuler = new Vector3(0f, 0f, 0f);

		public Vector3 lidOpenEuler = new Vector3(-70f, 0f, 0f);

		public float lidAnimSpeed = 5f;

		[Header("Lid Sounds")]
		public AudioClip lidOpenSound;

		public AudioClip lidCloseSound;

		[Header("Debug")]
		[Tooltip("Set to true in the Inspector to toggle the lid (Editor or Play). It will auto-reset to false in Play mode.")]
		public bool DebugLidToggle = false;

		[Header("Eject Settings")]
		[Tooltip("弹出时施加的速度大小(更小更慢)")]
		public float ejectVelocity = 0.12f;

		[Tooltip("是否直接设置刚体速度而不是 AddForce")]
		public bool setEjectVelocityDirectly = true;

		[Tooltip("弹出后临时设置的线性阻尼(drag),0 表示不改变。用于快速减速,单位为 drag")]
		public float temporaryPostEjectDrag = 1f;

		[Tooltip("弹出后恢复原始阻尼的延迟(秒)。")]
		public float restoreDragDelay = 0.5f;

		[Header("Inspector Debug Buttons")]
		[Tooltip("在 Inspector 中勾选以模拟 Play 按钮按下")]
		public bool DebugPressPlay = false;

		[Tooltip("在 Inspector 中勾选以模拟 Stop 按钮按下")]
		public bool DebugPressStop = false;

		[Tooltip("在 Inspector 中勾选以模拟 FastForward 按钮按下")]
		public bool DebugPressFF = false;

		[Tooltip("在 Inspector 中勾选以模拟 Rewind 按钮按下")]
		public bool DebugPressREW = false;

		private bool isLidOpen = false;

		private Quaternion targetRotation;

		private TapeMode currentMode = TapeMode.Normal;

		private bool pendingEject = false;

		private bool isEjecting = false;

		private bool wasPlayingBeforeFFREW = false;

		private const float DetectorReenableDelay = 1f;

		private const float EndTolerance = 0.02f;

		private void Start()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)lidTransform != (Object)null)
			{
				targetRotation = Quaternion.Euler(lidClosedEuler);
			}
			if ((Object)(object)detectorCollider == (Object)null && (Object)(object)tapeInsertPoint != (Object)null)
			{
				detectorCollider = ((Component)tapeInsertPoint).GetComponent<Collider>();
			}
			if ((Object)(object)sfxSource != (Object)null)
			{
				sfxSource.loop = false;
				sfxSource.clip = null;
			}
		}

		private void OnValidate()
		{
			if (!Application.isPlaying && DebugLidToggle)
			{
				ToggleLid();
			}
		}

		private void Update()
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			if (DebugPressPlay)
			{
				DebugPressPlay = false;
				Play();
			}
			if (DebugPressStop)
			{
				DebugPressStop = false;
				Stop();
			}
			if (DebugPressFF)
			{
				DebugPressFF = false;
				FastForward();
			}
			if (DebugPressREW)
			{
				DebugPressREW = false;
				Rewind();
			}
			if (Application.isPlaying && DebugLidToggle)
			{
				DebugLidToggle = false;
				ToggleLid();
			}
			if ((Object)(object)lidTransform != (Object)null)
			{
				lidTransform.localRotation = Quaternion.Lerp(lidTransform.localRotation, targetRotation, Time.deltaTime * lidAnimSpeed);
			}
			if ((Object)(object)insertedTape != (Object)null)
			{
				Transform val = ((!((Object)(object)tapeSlot != (Object)null)) ? ((Component)this).transform : tapeSlot);
				if ((Object)(object)((Component)insertedTape).transform.parent != (Object)(object)val)
				{
					((Component)insertedTape).transform.SetParent(val, false);
				}
				if ((Object)(object)tapeInsertPoint != (Object)null)
				{
					((Component)insertedTape).transform.position = tapeInsertPoint.position;
					((Component)insertedTape).transform.rotation = tapeInsertPoint.rotation;
				}
			}
			if ((Object)(object)((FVRInteractiveObject)this).m_hand != (Object)null && ((FVRInteractiveObject)this).m_hand.Input.TriggerDown)
			{
				ToggleLid();
			}
			if ((Object)(object)insertedTape != (Object)null && (Object)(object)audioSource != (Object)null && (Object)(object)audioSource.clip != (Object)null)
			{
				if (currentMode == TapeMode.FastForward)
				{
					insertedTape.currentTime = Mathf.Min(audioSource.clip.length, insertedTape.currentTime + ffSpeed * Time.deltaTime);
					audioSource.time = insertedTape.currentTime;
				}
				else if (currentMode == TapeMode.Rewind)
				{
					insertedTape.currentTime = Mathf.Max(0f, insertedTape.currentTime - rewSpeed * Time.deltaTime);
					audioSource.time = insertedTape.currentTime;
				}
				else
				{
					if (audioSource.isPlaying)
					{
						insertedTape.currentTime = audioSource.time;
					}
					if (audioSource.isPlaying && audioSource.time >= audioSource.clip.length - 0.02f)
					{
						OnPlaybackReachedEnd();
					}
				}
				if (insertedTape.currentTime >= audioSource.clip.length)
				{
					Stop();
				}
			}
			if (pendingEject && (Object)(object)insertedTape != (Object)null && isLidOpen && !isEjecting)
			{
				EjectTape();
				pendingEject = false;
			}
		}

		private void OnPlaybackReachedEnd()
		{
			if ((Object)(object)insertedTape == (Object)null || (Object)(object)audioSource == (Object)null || (Object)(object)audioSource.clip == (Object)null)
			{
				return;
			}
			try
			{
				audioSource.Stop();
				audioSource.time = audioSource.clip.length;
			}
			catch (Exception)
			{
			}
			insertedTape.currentTime = audioSource.clip.length;
			insertedTape.isFinished = true;
			StopLoopSound();
			currentMode = TapeMode.Normal;
			wasPlayingBeforeFFREW = false;
			try
			{
				insertedTape.HandleEndPrefabs();
			}
			catch (Exception)
			{
			}
		}

		[ContextMenu("Toggle Lid")]
		public void ToggleLid()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			isLidOpen = !isLidOpen;
			targetRotation = ((!isLidOpen) ? Quaternion.Euler(lidClosedEuler) : Quaternion.Euler(lidOpenEuler));
			if ((Object)(object)sfxSource != (Object)null)
			{
				if (isLidOpen && (Object)(object)lidOpenSound != (Object)null)
				{
					sfxSource.PlayOneShot(lidOpenSound);
				}
				else if (!isLidOpen && (Object)(object)lidCloseSound != (Object)null)
				{
					sfxSource.PlayOneShot(lidCloseSound);
				}
			}
		}

		public bool IsLidOpen()
		{
			return isLidOpen;
		}

		public bool HasInsertedTape()
		{
			return (Object)(object)insertedTape != (Object)null;
		}

		public void InsertTape(Tape tape)
		{
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)tape == (Object)null || !isLidOpen || (Object)(object)insertedTape != (Object)null || tape.isInserted)
			{
				return;
			}
			insertedTape = tape;
			audioSource.clip = tape.tapeAudio;
			audioSource.time = tape.currentTime;
			insertedTapeOriginalLayer = ((Component)tape).gameObject.layer;
			bool flag = false;
			try
			{
				FVRPhysicalObject val = (FVRPhysicalObject)(object)insertedTape;
				if ((Object)(object)val != (Object)null)
				{
					val.StoreAndDestroyRigidbody();
					flag = true;
				}
			}
			catch (Exception)
			{
			}
			Rigidbody component = ((Component)tape).GetComponent<Rigidbody>();
			Collider component2 = ((Component)tape).GetComponent<Collider>();
			if (!flag && (Object)(object)component != (Object)null)
			{
				component.velocity = Vector3.zero;
				component.angularVelocity = Vector3.zero;
				component.isKinematic = true;
				component.interpolation = (RigidbodyInterpolation)1;
				component.collisionDetectionMode = (CollisionDetectionMode)1;
			}
			bool flag2 = false;
			try
			{
				FVRPhysicalObject val2 = (FVRPhysicalObject)(object)insertedTape;
				if ((Object)(object)val2 != (Object)null && (Object)(object)tapeSlot != (Object)null)
				{
					val2.SetParentage(tapeSlot);
					flag2 = true;
				}
			}
			catch (Exception)
			{
				flag2 = false;
			}
			if (!flag2)
			{
				if ((Object)(object)tapeSlot != (Object)null)
				{
					((Component)tape).transform.SetParent(tapeSlot, false);
				}
				else
				{
					((Component)tape).transform.SetParent(((Component)this).transform, false);
				}
			}
			if ((Object)(object)tapeInsertPoint != (Object)null)
			{
				((Component)tape).transform.position = tapeInsertPoint.position;
				((Component)tape).transform.rotation = tapeInsertPoint.rotation;
			}
			else
			{
				((Component)tape).transform.localPosition = Vector3.zero;
				((Component)tape).transform.localRotation = Quaternion.identity;
			}
			try
			{
				((MonoBehaviour)this).StartCoroutine(DisableCollidersNextFrame(tape));
			}
			catch (Exception)
			{
				if (!flag && (Object)(object)component2 != (Object)null)
				{
					component2.enabled = false;
				}
			}
			bool flag3 = false;
			try
			{
				FVRPhysicalObject val3 = (FVRPhysicalObject)(object)insertedTape;
				if ((Object)(object)val3 != (Object)null)
				{
					((FVRInteractiveObject)val3).SetAllCollidersToLayer(false, "NoCol");
					flag3 = true;
				}
			}
			catch (Exception)
			{
			}
			if (!flag3)
			{
				int num = LayerMask.NameToLayer("NoCol");
				if (num != -1 && (tape.collidersToDisable == null || tape.collidersToDisable.Length == 0))
				{
					((Component)tape).gameObject.layer = num;
				}
			}
			tape.isInserted = true;
			if ((Object)(object)insertSound != (Object)null && (Object)(object)sfxSource != (Object)null)
			{
				sfxSource.PlayOneShot(insertSound);
			}
			if ((Object)(object)detectorCollider != (Object)null)
			{
				detectorCollider.enabled = false;
			}
			((MonoBehaviour)this).Invoke("ReEnableDetector", 1f);
		}

		private IEnumerator DisableCollidersNextFrame(Tape tape)
		{
			yield return null;
			if ((Object)(object)tape != (Object)null)
			{
				try
				{
					tape.DisableAssignedColliders();
				}
				catch (Exception)
				{
				}
			}
		}

		public void EjectTape()
		{
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: 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_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)insertedTape == (Object)null || !isLidOpen || isEjecting)
			{
				return;
			}
			isEjecting = true;
			if ((Object)(object)audioSource != (Object)null)
			{
				insertedTape.currentTime = audioSource.time;
			}
			audioSource.Stop();
			audioSource.clip = null;
			StopLoopSound();
			try
			{
				insertedTape.RestoreAssignedColliders();
			}
			catch (Exception)
			{
			}
			bool flag = false;
			try
			{
				FVRPhysicalObject val = (FVRPhysicalObject)(object)insertedTape;
				if ((Object)(object)val != (Object)null)
				{
					val.SetParentage((Transform)null);
					val.RecoverRigidbody();
					((FVRInteractiveObject)val).SetAllCollidersToLayer(false, "Default");
					flag = true;
				}
			}
			catch (Exception)
			{
			}
			if (!flag)
			{
				((Component)insertedTape).transform.SetParent((Transform)null, true);
				Rigidbody component = ((Component)insertedTape).GetComponent<Rigidbody>();
				Collider component2 = ((Component)insertedTape).GetComponent<Collider>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.enabled = true;
				}
				if ((Object)(object)component != (Object)null)
				{
					component.velocity = Vector3.zero;
					component.angularVelocity = Vector3.zero;
					component.isKinematic = false;
					component.interpolation = (RigidbodyInterpolation)1;
					component.collisionDetectionMode = (CollisionDetectionMode)1;
				}
			}
			if ((Object)(object)ejectPoint != (Object)null)
			{
				((Component)insertedTape).transform.position = ejectPoint.position;
				((Component)insertedTape).transform.rotation = ejectPoint.rotation;
			}
			else
			{
				Vector3 val2 = ((!((Object)(object)tapeInsertPoint != (Object)null)) ? ((Component)this).transform.up : tapeInsertPoint.forward);
				Vector3 position = ((!((Object)(object)tapeInsertPoint != (Object)null)) ? (((Component)insertedTape).transform.position + val2 * 0.05f) : (tapeInsertPoint.position + val2 * 0.05f));
				((Component)insertedTape).transform.position = position;
			}
			Rigidbody component3 = ((Component)insertedTape).GetComponent<Rigidbody>();
			if ((Object)(object)component3 != (Object)null)
			{
				Vector3 val3 = (((Object)(object)ejectPoint != (Object)null) ? ejectPoint.forward : ((!((Object)(object)tapeInsertPoint != (Object)null)) ? ((Component)this).transform.up : tapeInsertPoint.forward));
				Vector3 val4 = ((Vector3)(ref val3)).normalized * Mathf.Max(0f, ejectVelocity);
				component3.velocity = Vector3.zero;
				component3.angularVelocity = Vector3.zero;
				if (setEjectVelocityDirectly)
				{
					component3.velocity = val4;
				}
				else
				{
					component3.AddForce(val4, (ForceMode)2);
				}
				if (temporaryPostEjectDrag > 0f)
				{
					float drag = component3.drag;
					component3.drag = temporaryPostEjectDrag;
					((MonoBehaviour)this).StartCoroutine(RestoreDrag(component3, drag, restoreDragDelay));
				}
			}
			if (insertedTapeOriginalLayer >= 0)
			{
				((Component)insertedTape).gameObject.layer = insertedTapeOriginalLayer;
				insertedTapeOriginalLayer = -1;
			}
			if ((Object)(object)ejectSound != (Object)null && (Object)(object)sfxSource != (Object)null)
			{
				sfxSource.PlayOneShot(ejectSound);
			}
			if ((Object)(object)detectorCollider != (Object)null)
			{
				detectorCollider.enabled = false;
			}
			((MonoBehaviour)this).Invoke("ReEnableDetector", 1f);
			insertedTape.isInserted = false;
			insertedTape = null;
			isEjecting = false;
		}

		private IEnumerator RestoreDrag(Rigidbody rb, float originalDrag, float delay)
		{
			if ((Object)(object)rb == (Object)null)
			{
				yield break;
			}
			yield return (object)new WaitForSeconds(delay);
			try
			{
				if ((Object)(object)rb != (Object)null)
				{
					rb.drag = originalDrag;
				}
			}
			catch (Exception)
			{
			}
		}

		private void ReEnableDetector()
		{
			if (!((Object)(object)detectorCollider == (Object)null))
			{
				if ((Object)(object)insertedTape != (Object)null)
				{
					((MonoBehaviour)this).Invoke("ReEnableDetector", 0.5f);
				}
				else
				{
					detectorCollider.enabled = true;
				}
			}
		}

		public void Play()
		{
			if (!((Object)(object)insertedTape == (Object)null) && !((Object)(object)audioSource == (Object)null) && !((Object)(object)audioSource.clip == (Object)null))
			{
				currentMode = TapeMode.Normal;
				StopLoopSound();
				audioSource.loop = false;
				audioSource.time = insertedTape.currentTime;
				audioSource.Play();
				PlayButtonClick();
				if (!insertedTape.isFinished && (Object)(object)insertedTape.tapeAudio != (Object)null && insertedTape.currentTime < insertedTape.tapeAudio.length)
				{
					insertedTape.OnPlayStart();
				}
				StopFFREW();
			}
		}

		public void Stop()
		{
			if (!((Object)(object)insertedTape == (Object)null))
			{
				StopFFREW();
				wasPlayingBeforeFFREW = false;
				if ((Object)(object)audioSource != (Object)null)
				{
					insertedTape.currentTime = audioSource.time;
				}
				if ((Object)(object)audioSource != (Object)null)
				{
					audioSource.Pause();
				}
				currentMode = TapeMode.Normal;
				StopLoopSound();
				PlayButtonClick();
				if (isLidOpen)
				{
					pendingEject = true;
				}
			}
		}

		public void FastForward()
		{
			if (!((Object)(object)insertedTape == (Object)null) && !((Object)(object)audioSource == (Object)null) && !((Object)(object)audioSource.clip == (Object)null))
			{
				insertedTape.currentTime = audioSource.time;
				wasPlayingBeforeFFREW = audioSource.isPlaying;
				currentMode = TapeMode.FastForward;
				audioSource.Pause();
				PlayLoopSound(ffSound);
				PlayButtonClick();
			}
		}

		public void Rewind()
		{
			if (!((Object)(object)insertedTape == (Object)null) && !((Object)(object)audioSource == (Object)null) && !((Object)(object)audioSource.clip == (Object)null))
			{
				insertedTape.currentTime = audioSource.time;
				wasPlayingBeforeFFREW = audioSource.isPlaying;
				currentMode = TapeMode.Rewind;
				audioSource.Pause();
				PlayLoopSound(rewSound);
				PlayButtonClick();
			}
		}

		public void StopFFREW()
		{
			currentMode = TapeMode.Normal;
			StopLoopSound();
			if ((Object)(object)insertedTape != (Object)null && (Object)(object)audioSource != (Object)null && (Object)(object)audioSource.clip != (Object)null && wasPlayingBeforeFFREW)
			{
				audioSource.time = insertedTape.currentTime;
				audioSource.Play();
			}
			wasPlayingBeforeFFREW = false;
		}

		public void PlayButtonClick()
		{
			if ((Object)(object)buttonClickSound != (Object)null && (Object)(object)sfxSource != (Object)null)
			{
				sfxSource.PlayOneShot(buttonClickSound);
			}
		}

		private void PlayLoopSound(AudioClip clip)
		{
			if (!((Object)(object)sfxSource == (Object)null) && !((Object)(object)clip == (Object)null) && (!sfxSource.isPlaying || !((Object)(object)sfxSource.clip == (Object)(object)clip) || !sfxSource.loop))
			{
				sfxSource.clip = clip;
				sfxSource.loop = true;
				sfxSource.Play();
			}
		}

		private void StopLoopSound()
		{
			if (!((Object)(object)sfxSource == (Object)null))
			{
				sfxSource.Stop();
				sfxSource.loop = false;
				sfxSource.clip = null;
			}
		}

		public void ResetAllButtons(SonyWalkmanButton except)
		{
			SonyWalkmanButton[] array = new SonyWalkmanButton[4] { playButton, stopButton, ffButton, rewButton };
			SonyWalkmanButton[] array2 = array;
			foreach (SonyWalkmanButton sonyWalkmanButton in array2)
			{
				if ((Object)(object)sonyWalkmanButton != (Object)null && (Object)(object)sonyWalkmanButton != (Object)(object)except)
				{
					sonyWalkmanButton.ResetButton();
				}
			}
		}

		private void OnTriggerEnter(Collider other)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			Tape component = ((Component)other).GetComponent<Tape>();
			if (!((Object)(object)component != (Object)null) || !isLidOpen || (!((Object)(object)detectorCollider == (Object)null) && !detectorCollider.enabled) || component.isInserted || !((Object)(object)insertedTape == (Object)null))
			{
				return;
			}
			if ((Object)(object)tapeInsertPoint != (Object)null)
			{
				float num = 0.05f;
				if (Vector3.Distance(((Component)other).transform.position, tapeInsertPoint.position) <= num)
				{
					InsertTape(component);
				}
			}
			else
			{
				InsertTape(component);
			}
		}

		private void OnTriggerExit(Collider other)
		{
		}
	}
	public class SonyWalkmanButton : FVRInteractiveObject
	{
		public enum ButtonType
		{
			Play,
			Stop,
			FF,
			REW,
			Volume
		}

		public ButtonType buttonType;

		public SonyWalkman walkman;

		[Header("Button Animation Points")]
		public Transform buttonUpPoint;

		public Transform buttonDownPoint;

		[Header("Volume (optional)")]
		[Tooltip("优先使用此 AudioSource;若为空会尝试从 walkman 上获取 audioSource。")]
		public AudioSource targetAudioSource;

		[Range(0f, 1f)]
		public float highVolume = 1f;

		[Range(0f, 1f)]
		public float lowVolume = 0.1f;

		[Tooltip("切换时的过渡时长(秒)。")]
		public float transitionDuration = 0.5f;

		[Tooltip("是否在 Start 时把音量设为 High(否则设为 Low)。")]
		public bool startHigh = true;

		private bool isPressed = false;

		[Header("Volume State (read-only)")]
		public bool isHigh = true;

		private Coroutine _volCoroutine;

		public override void Awake()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			((FVRInteractiveObject)this).Awake();
			if ((Object)(object)buttonUpPoint != (Object)null)
			{
				((Component)this).transform.position = buttonUpPoint.position;
				((Component)this).transform.rotation = buttonUpPoint.rotation;
			}
		}

		private void Start()
		{
			if ((Object)(object)targetAudioSource == (Object)null)
			{
				if ((Object)(object)walkman != (Object)null && (Object)(object)walkman.audioSource != (Object)null)
				{
					targetAudioSource = walkman.audioSource;
				}
				else
				{
					targetAudioSource = ((Component)this).GetComponent<AudioSource>();
					if ((Object)(object)targetAudioSource == (Object)null && (Object)(object)((Component)this).transform.parent != (Object)null)
					{
						targetAudioSource = ((Component)((Component)this).transform.parent).GetComponentInChildren<AudioSource>();
					}
				}
			}
			if ((Object)(object)targetAudioSource != (Object)null)
			{
				isHigh = startHigh;
				targetAudioSource.volume = ((!isHigh) ? lowVolume : highVolume);
			}
		}

		public override void SimpleInteraction(FVRViveHand hand)
		{
			((FVRInteractiveObject)this).SimpleInteraction(hand);
			switch (buttonType)
			{
			case ButtonType.Play:
				if ((Object)(object)walkman != (Object)null)
				{
					walkman.Play();
				}
				MoveToDownPoint();
				if ((Object)(object)walkman != (Object)null)
				{
					walkman.ResetAllButtons(this);
				}
				break;
			case ButtonType.Stop:
				if ((Object)(object)walkman != (Object)null)
				{
					walkman.Stop();
				}
				MoveToDownPoint();
				if ((Object)(object)walkman != (Object)null)
				{
					walkman.ResetAllButtons(this);
				}
				break;
			case ButtonType.FF:
				ToggleFFREW(isFF: true);
				if ((Object)(object)walkman != (Object)null)
				{
					walkman.ResetAllButtons(this);
				}
				break;
			case ButtonType.REW:
				ToggleFFREW(isFF: false);
				if ((Object)(object)walkman != (Object)null)
				{
					walkman.ResetAllButtons(this);
				}
				break;
			case ButtonType.Volume:
				ToggleVolume();
				MoveToDownPoint();
				if ((Object)(object)walkman != (Object)null)
				{
					walkman.ResetAllButtons(this);
				}
				break;
			}
			if ((Object)(object)walkman != (Object)null)
			{
				walkman.PlayButtonClick();
			}
		}

		private void ToggleFFREW(bool isFF)
		{
			isPressed = !isPressed;
			if (isPressed)
			{
				if ((Object)(object)walkman != (Object)null)
				{
					if (isFF)
					{
						walkman.FastForward();
					}
					else
					{
						walkman.Rewind();
					}
				}
				MoveToDownPoint();
			}
			else
			{
				if ((Object)(object)walkman != (Object)null)
				{
					walkman.StopFFREW();
				}
				MoveToUpPoint();
			}
		}

		private void ToggleVolume()
		{
			if ((Object)(object)targetAudioSource == (Object)null)
			{
				Debug.LogWarning((object)"[SonyWalkmanButton] No target AudioSource for volume toggle.");
				return;
			}
			float volume = targetAudioSource.volume;
			float to = ((!isHigh) ? highVolume : lowVolume);
			isHigh = !isHigh;
			if (_volCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(_volCoroutine);
			}
			_volCoroutine = ((MonoBehaviour)this).StartCoroutine(SmoothVolume(volume, to, transitionDuration));
		}

		public void SetVolumeHigh(bool high)
		{
			if (!((Object)(object)targetAudioSource == (Object)null))
			{
				if (_volCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(_volCoroutine);
				}
				isHigh = high;
				targetAudioSource.volume = ((!isHigh) ? lowVolume : highVolume);
			}
		}

		private IEnumerator SmoothVolume(float from, float to, float duration)
		{
			if ((Object)(object)targetAudioSource == (Object)null)
			{
				_volCoroutine = null;
				yield break;
			}
			if (duration <= 0f)
			{
				targetAudioSource.volume = to;
				_volCoroutine = null;
				yield break;
			}
			float elapsed = 0f;
			while (elapsed < duration)
			{
				elapsed += Time.deltaTime;
				float t = Mathf.Clamp01(elapsed / duration);
				float v = Mathf.Lerp(from, to, t);
				targetAudioSource.volume = v;
				yield return null;
			}
			targetAudioSource.volume = to;
			_volCoroutine = null;
		}

		public void ResetButton()
		{
			isPressed = false;
			MoveToUpPoint();
		}

		private void MoveToDownPoint()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)buttonDownPoint != (Object)null)
			{
				((Component)this).transform.position = buttonDownPoint.position;
				((Component)this).transform.rotation = buttonDownPoint.rotation;
			}
		}

		private void MoveToUpPoint()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)buttonUpPoint != (Object)null)
			{
				((Component)this).transform.position = buttonUpPoint.position;
				((Component)this).transform.rotation = buttonUpPoint.rotation;
			}
		}
	}
	public class Tape : FVRPhysicalObject
	{
		[Header("Tape Settings")]
		public AudioClip tapeAudio;

		[HideInInspector]
		public float currentTime = 0f;

		[Header("State")]
		public bool isInserted = false;

		public bool isFinished = false;

		[Header("Debug")]
		public bool debugResetTime = false;

		[Header("Prefab Actions - Play Start")]
		public GameObject[] prefabsOnPlay;

		public Transform[] playSpawnPoints;

		public GameObject[] prefabsToDestroyOnPlay;

		[Header("Prefab Actions - Play End")]
		public GameObject[] prefabsOnEnd;

		public Transform[] endSpawnPoints;

		public GameObject[] prefabsToDestroyOnEnd;

		[Header("Collision Control")]
		public Collider[] collidersToDisable;

		public bool preferDisableGameObject = true;

		public bool preferLayerNoCol = true;

		private GameObject[] spawnedPlayPrefabs;

		private GameObject[] spawnedEndPrefabs;

		private bool playPrefabsSpawned = false;

		private bool endPrefabsSpawned = false;

		private bool[] _prevColliderEnabled;

		private int[] _prevColliderLayer;

		private bool[] _prevGameObjectActive;

		private void Update()
		{
			if (debugResetTime)
			{
				debugResetTime = false;
				ResetTape();
			}
			if ((Object)(object)tapeAudio != (Object)null && currentTime >= tapeAudio.length && !isFinished)
			{
				isFinished = true;
				HandleEndPrefabs();
			}
		}

		public void FastForward(float seconds)
		{
			if (!((Object)(object)tapeAudio == (Object)null))
			{
				currentTime = Mathf.Min(tapeAudio.length, currentTime + seconds);
				if (currentTime >= tapeAudio.length)
				{
					isFinished = true;
				}
			}
		}

		public void Rewind(float seconds)
		{
			if (!((Object)(object)tapeAudio == (Object)null))
			{
				currentTime = Mathf.Max(0f, currentTime - seconds);
				if (currentTime < tapeAudio.length)
				{
					isFinished = false;
				}
			}
		}

		public void ResetTape()
		{
			currentTime = 0f;
			isFinished = false;
			ClearPlayPrefabs();
			ClearEndPrefabs();
			playPrefabsSpawned = false;
			endPrefabsSpawned = false;
		}

		public float GetProgress()
		{
			if ((Object)(object)tapeAudio == (Object)null || tapeAudio.length <= 0f)
			{
				return 0f;
			}
			return Mathf.Clamp01(currentTime / tapeAudio.length);
		}

		public void AttachToSlot(Transform slot)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)slot != (Object)null)
			{
				((Component)this).transform.SetParent(slot, false);
				((Component)this).transform.localPosition = Vector3.zero;
				((Component)this).transform.localRotation = Quaternion.identity;
			}
			else
			{
				((Component)this).transform.SetParent((Transform)null);
			}
			isInserted = true;
			Rigidbody component = ((Component)this).GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null)
			{
				component.velocity = Vector3.zero;
				component.angularVelocity = Vector3.zero;
			}
		}

		public void DetachFromSlot()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.SetParent((Transform)null, true);
			isInserted = false;
			Rigidbody component = ((Component)this).GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null)
			{
				component.velocity = Vector3.zero;
				component.angularVelocity = Vector3.zero;
			}
		}

		public void DisableAssignedColliders()
		{
			if (collidersToDisable == null || collidersToDisable.Length == 0)
			{
				return;
			}
			int num = collidersToDisable.Length;
			_prevColliderEnabled = new bool[num];
			_prevColliderLayer = new int[num];
			_prevGameObjectActive = new bool[num];
			int num2 = LayerMask.NameToLayer("NoCol");
			for (int i = 0; i < num; i++)
			{
				Collider val = collidersToDisable[i];
				if ((Object)(object)val == (Object)null)
				{
					_prevColliderEnabled[i] = false;
					_prevColliderLayer[i] = -1;
					_prevGameObjectActive[i] = false;
					continue;
				}
				_prevColliderEnabled[i] = val.enabled;
				_prevColliderLayer[i] = ((Component)val).gameObject.layer;
				_prevGameObjectActive[i] = ((Component)val).gameObject.activeSelf;
				if (preferDisableGameObject)
				{
					try
					{
						((Component)val).gameObject.SetActive(false);
					}
					catch (Exception)
					{
					}
				}
				else if (preferLayerNoCol && num2 != -1)
				{
					try
					{
						((Component)val).gameObject.layer = num2;
					}
					catch (Exception)
					{
					}
				}
				else
				{
					try
					{
						val.enabled = false;
					}
					catch (Exception)
					{
					}
				}
			}
		}

		public void RestoreAssignedColliders()
		{
			if (collidersToDisable == null || collidersToDisable.Length == 0 || _prevColliderEnabled == null || _prevColliderLayer == null || _prevGameObjectActive == null)
			{
				return;
			}
			int num = collidersToDisable.Length;
			for (int i = 0; i < num; i++)
			{
				Collider val = collidersToDisable[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				bool active = _prevGameObjectActive[i];
				try
				{
					((Component)val).gameObject.SetActive(active);
				}
				catch (Exception)
				{
				}
				int num2 = _prevColliderLayer[i];
				if (num2 >= 0)
				{
					try
					{
						((Component)val).gameObject.layer = num2;
					}
					catch (Exception)
					{
					}
				}
				bool enabled = _prevColliderEnabled[i];
				try
				{
					val.enabled = enabled;
				}
				catch (Exception)
				{
				}
			}
			_prevColliderEnabled = null;
			_prevColliderLayer = null;
			_prevGameObjectActive = null;
		}

		public void OnPlayStart()
		{
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			if (isFinished || playPrefabsSpawned)
			{
				return;
			}
			if (prefabsToDestroyOnPlay != null)
			{
				GameObject[] array = prefabsToDestroyOnPlay;
				foreach (GameObject val in array)
				{
					if ((Object)(object)val != (Object)null)
					{
						Object.Destroy((Object)(object)val);
					}
				}
			}
			if (prefabsOnPlay != null && playSpawnPoints != null)
			{
				int num = Mathf.Min(prefabsOnPlay.Length, playSpawnPoints.Length);
				spawnedPlayPrefabs = (GameObject[])(object)new GameObject[num];
				for (int j = 0; j < num; j++)
				{
					if ((Object)(object)prefabsOnPlay[j] != (Object)null && (Object)(object)playSpawnPoints[j] != (Object)null)
					{
						spawnedPlayPrefabs[j] = Object.Instantiate<GameObject>(prefabsOnPlay[j], playSpawnPoints[j].position, playSpawnPoints[j].rotation);
					}
				}
			}
			playPrefabsSpawned = true;
		}

		public void HandleEndPrefabs()
		{
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			if (endPrefabsSpawned)
			{
				return;
			}
			if (prefabsToDestroyOnEnd != null)
			{
				GameObject[] array = prefabsToDestroyOnEnd;
				foreach (GameObject val in array)
				{
					if ((Object)(object)val != (Object)null)
					{
						Object.Destroy((Object)(object)val);
					}
				}
			}
			if (prefabsOnEnd != null && endSpawnPoints != null)
			{
				int num = Mathf.Min(prefabsOnEnd.Length, endSpawnPoints.Length);
				spawnedEndPrefabs = (GameObject[])(object)new GameObject[num];
				for (int j = 0; j < num; j++)
				{
					if ((Object)(object)prefabsOnEnd[j] != (Object)null && (Object)(object)endSpawnPoints[j] != (Object)null)
					{
						spawnedEndPrefabs[j] = Object.Instantiate<GameObject>(prefabsOnEnd[j], endSpawnPoints[j].position, endSpawnPoints[j].rotation);
					}
				}
			}
			endPrefabsSpawned = true;
		}

		public void ClearPlayPrefabs()
		{
			if (spawnedPlayPrefabs == null)
			{
				return;
			}
			for (int i = 0; i < spawnedPlayPrefabs.Length; i++)
			{
				if ((Object)(object)spawnedPlayPrefabs[i] != (Object)null)
				{
					Object.Destroy((Object)(object)spawnedPlayPrefabs[i]);
					spawnedPlayPrefabs[i] = null;
				}
			}
		}

		public void ClearEndPrefabs()
		{
			if (spawnedEndPrefabs == null)
			{
				return;
			}
			for (int i = 0; i < spawnedEndPrefabs.Length; i++)
			{
				if ((Object)(object)spawnedEndPrefabs[i] != (Object)null)
				{
					Object.Destroy((Object)(object)spawnedEndPrefabs[i]);
					spawnedEndPrefabs[i] = null;
				}
			}
		}
	}
	public class TapeInsertTrigger : MonoBehaviour
	{
		public SonyWalkman walkman;

		public float maxInsertDistance = 0.05f;

		private void OnTriggerEnter(Collider other)
		{
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)walkman == (Object)null))
			{
				Tape component = ((Component)other).GetComponent<Tape>();
				if (!((Object)(object)component == (Object)null) && walkman.IsLidOpen() && !walkman.HasInsertedTape() && !(Vector3.Distance(((Component)other).transform.position, ((Component)this).transform.position) > maxInsertDistance))
				{
					walkman.InsertTape(component);
				}
			}
		}
	}
}