Decompiled source of PhonkRowing v1.2.0

PhonkRowingMod.dll

Decompiled 13 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Managers;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
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: AssemblyTitle("PhonkRowingMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PhonkRowingMod")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("83e1673e-d416-4d9a-bbe4-bdeec8c56ee9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PhonkRowingMod;

[BepInPlugin("com.yourname.phonkrowing", "Phonk Rowing", "1.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class PhonkRowingPlugin : BaseUnityPlugin
{
	public static PhonkRowingPlugin Instance;

	private AudioSource _audioSource;

	private List<AudioClip> _playlist = new List<AudioClip>();

	private List<string> _trackNames = new List<string>();

	private int _currentTrackIndex = 0;

	private bool _isPausedByPlayer = false;

	private ConfigEntry<float> _musicVolume;

	private float _timeOffShip = 0f;

	private const float StopDelay = 2f;

	private GameObject _playerPanel;

	private RectTransform _panelRect;

	private Text _trackNameText;

	private Button _playPauseButton;

	private Text _playPauseText;

	private Slider _volumeSlider;

	private GameObject _hudPanel;

	private Text _hudText;

	private Outline _hudOutline;

	private bool _rpcRegistered = false;

	private bool _isLoading = false;

	private bool _isPanelOpen = false;

	private Coroutine _animationCoroutine;

	private float _savedTime = 0f;

	private int _savedIndex = 0;

	private FieldInfo _attachStopTimeField;

	private bool _cachedIsOnShip = false;

	private int _lastDisplayedTrackIndex = -1;

	private readonly Collider[] _overlapBuffer = (Collider[])(object)new Collider[10];

	private Vector3 _lastPlayerPos = Vector3.zero;

	public bool IsMenuOpen = false;

	public bool IsInventoryOpen = false;

	private string _lastTrackName = null;

	private float _lastTrackStartTime = 0f;

	private float _lastRpcTime = 0f;

	private Vector2 _targetPos = new Vector2(0f, -20f);

	private Vector2 _startPos = new Vector2(0f, -200f);

	private float[] _spectrumData = new float[256];

	private float _targetBassIntensity = 0f;

	private float _currentBassIntensity = 0f;

	private string _lastHudString = "";

	private WaitForSeconds _waitBeat;

	private WaitForSeconds _waitShipCheck;

	private WaitForSeconds _waitRpcCheck;

	private void Awake()
	{
		//IL_000c: 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_002c: Expected O, but got Unknown
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Expected O, but got Unknown
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Expected O, but got Unknown
		Instance = this;
		new Harmony("com.yourname.phonkrowing").PatchAll(Assembly.GetExecutingAssembly());
		_waitBeat = new WaitForSeconds(0.1f);
		_waitShipCheck = new WaitForSeconds(0.5f);
		_waitRpcCheck = new WaitForSeconds(1f);
		_musicVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "Music Volume", 0.7f, new ConfigDescription("Громкость музыки на корабле", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		GameObject val = new GameObject("PhonkAudioSource");
		Object.DontDestroyOnLoad((Object)(object)val);
		_audioSource = val.AddComponent<AudioSource>();
		_audioSource.loop = false;
		_audioSource.volume = _musicVolume.Value;
		_attachStopTimeField = typeof(Player).GetField("m_attachStopTime", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		((MonoBehaviour)this).StartCoroutine(LoadAudio());
		((MonoBehaviour)this).StartCoroutine(ShipCheckCoroutine());
		((MonoBehaviour)this).StartCoroutine(RpcRegistrationCoroutine());
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Мод Phonk Rowing загружен (Final Optimized HUD)!");
	}

	private IEnumerator ShipCheckCoroutine()
	{
		while (true)
		{
			yield return _waitShipCheck;
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				continue;
			}
			if ((Object)(object)((Character)localPlayer).GetStandingOnShip() != (Object)null || (Object)(object)localPlayer.GetControlledShip() != (Object)null)
			{
				_cachedIsOnShip = true;
				_lastPlayerPos = ((Component)localPlayer).transform.position;
				continue;
			}
			if (((Character)localPlayer).IsSitting() && (Object)(object)((Component)localPlayer).transform.parent != (Object)null && (Object)(object)((Component)((Component)localPlayer).transform.parent).GetComponentInParent<Ship>() != (Object)null)
			{
				_cachedIsOnShip = true;
				continue;
			}
			if (_attachStopTimeField != null)
			{
				float attachStopTime = (float)_attachStopTimeField.GetValue(localPlayer);
				if (attachStopTime > Time.time)
				{
					_cachedIsOnShip = FastPhysicsShipCheck(((Component)localPlayer).transform.position, 10f);
					if (_cachedIsOnShip)
					{
						continue;
					}
				}
			}
			if (Vector3.Distance(((Component)localPlayer).transform.position, _lastPlayerPos) > 0.5f || _cachedIsOnShip)
			{
				_lastPlayerPos = ((Component)localPlayer).transform.position;
				_cachedIsOnShip = FastPhysicsShipCheck(((Component)localPlayer).transform.position, 2.5f);
			}
		}
	}

	private bool FastPhysicsShipCheck(Vector3 position, float radius)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		int num = Physics.OverlapSphereNonAlloc(position, radius, _overlapBuffer);
		for (int i = 0; i < num; i++)
		{
			if ((Object)(object)((Component)_overlapBuffer[i]).GetComponent<Ship>() != (Object)null || (Object)(object)((Component)_overlapBuffer[i]).GetComponentInParent<Ship>() != (Object)null)
			{
				return true;
			}
		}
		return false;
	}

	private IEnumerator RpcRegistrationCoroutine()
	{
		while (!_rpcRegistered)
		{
			if (ZRoutedRpc.instance != null)
			{
				ZRoutedRpc.instance.Register<string, float>("PhonkRowing_PlayTrack", (Action<long, string, float>)RPC_PlayTrack);
				ZRoutedRpc.instance.Register("PhonkRowing_PauseTrack", (Action<long>)RPC_PauseTrack);
				ZRoutedRpc.instance.Register("PhonkRowing_StopTrack", (Action<long>)RPC_StopTrack);
				_rpcRegistered = true;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Сетевые RPC методы зарегистрированы.");
			}
			yield return _waitRpcCheck;
		}
	}

	private void Update()
	{
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || (Object)(object)_audioSource == (Object)null)
		{
			return;
		}
		if ((Object)(object)_playerPanel == (Object)null && (Object)(object)InventoryGui.instance != (Object)null)
		{
			CreatePlayerUI();
		}
		if ((Object)(object)_playerPanel != (Object)null)
		{
			bool flag = (Object)(object)InventoryGui.instance != (Object)null && InventoryGui.instance.IsContainerOpen();
			bool flag2 = _cachedIsOnShip && IsInventoryOpen && !flag && !IsMenuOpen;
			if (flag2 && !_isPanelOpen)
			{
				_isPanelOpen = true;
				if (_animationCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(_animationCoroutine);
				}
				_animationCoroutine = ((MonoBehaviour)this).StartCoroutine(AnimatePanel());
			}
			else if (!flag2 && _isPanelOpen)
			{
				_isPanelOpen = false;
				if (_animationCoroutine != null)
				{
					((MonoBehaviour)this).StopCoroutine(_animationCoroutine);
				}
				_playerPanel.SetActive(false);
				_panelRect.anchoredPosition = _startPos;
			}
		}
		if ((Object)(object)_hudPanel != (Object)null)
		{
			bool flag3 = (Object)(object)InventoryGui.instance != (Object)null && InventoryGui.instance.IsContainerOpen();
			bool flag4 = _cachedIsOnShip && _playlist.Count > 0 && !IsMenuOpen && _audioSource.isPlaying && !IsInventoryOpen && !flag3;
			_hudPanel.SetActive(flag4);
			if (flag4 && _trackNames.Count > _currentTrackIndex)
			{
				string text = "\ud83c\udfb5 PLAY: " + _trackNames[_currentTrackIndex];
				if (_lastHudString != text)
				{
					_hudText.text = text;
					_lastHudString = text;
				}
				if ((Object)(object)_hudOutline != (Object)null && _audioSource.isPlaying)
				{
					_currentBassIntensity = Mathf.Lerp(_currentBassIntensity, _targetBassIntensity, Time.deltaTime * 10f);
					float num = Mathf.Max(0.1f, _audioSource.volume);
					float num2 = _currentBassIntensity / num;
					float num3 = Mathf.Clamp01(num2 * 10f);
					float num4 = 1f + num3 * 0.15f;
					((Component)_hudText).transform.localScale = new Vector3(num4, num4, 1f);
					float num5 = 3.5f;
					((Shadow)_hudOutline).effectDistance = new Vector2(num5, num5);
					float num6 = Mathf.Lerp(0.4f, 1f, num3);
					((Shadow)_hudOutline).effectColor = new Color(num6, 0f, 0f, 1f);
				}
			}
			else if ((Object)(object)_hudText != (Object)null)
			{
				((Component)_hudText).transform.localScale = Vector3.one;
			}
		}
		if (IsMenuOpen)
		{
			_timeOffShip = 0f;
		}
		else if (_cachedIsOnShip)
		{
			_timeOffShip = 0f;
			if (_audioSource.isPlaying || _isPausedByPlayer || _playlist.Count <= 0)
			{
				return;
			}
			if (_lastTrackName != null && _audioSource.time >= _playlist[_currentTrackIndex].length - 0.2f)
			{
				PlayNextTrackAndBroadcast();
			}
			else
			{
				if (string.IsNullOrEmpty(_lastTrackName))
				{
					return;
				}
				int num7 = _trackNames.IndexOf(_lastTrackName);
				if (num7 != -1)
				{
					float num8 = _lastTrackStartTime + (Time.time - _lastRpcTime);
					if (num8 >= 0f && num8 < _playlist[num7].length)
					{
						_currentTrackIndex = num7;
						_audioSource.clip = _playlist[_currentTrackIndex];
						_audioSource.time = num8;
						_audioSource.Play();
						UpdateUITrackName(force: true);
						UpdateUIButtonState();
					}
				}
			}
		}
		else if (_audioSource.isPlaying)
		{
			_timeOffShip += Time.deltaTime;
			if (_timeOffShip > 2f)
			{
				_audioSource.Pause();
			}
		}
	}

	private IEnumerator BeatAnalysisCoroutine()
	{
		while (true)
		{
			if ((Object)(object)_audioSource != (Object)null && _audioSource.isPlaying && (Object)(object)_hudPanel != (Object)null && _hudPanel.activeSelf)
			{
				_audioSource.GetSpectrumData(_spectrumData, 0, (FFTWindow)5);
				float bassSum = 0f;
				for (int i = 0; i < 10; i++)
				{
					bassSum += _spectrumData[i];
				}
				_targetBassIntensity = bassSum / 10f;
			}
			else
			{
				_targetBassIntensity = 0f;
			}
			yield return _waitBeat;
		}
	}

	private IEnumerator AnimatePanel()
	{
		float duration = 0.25f;
		float elapsed = 0f;
		_playerPanel.SetActive(true);
		_panelRect.anchoredPosition = _startPos;
		while (elapsed < duration)
		{
			elapsed += Time.deltaTime;
			float t = elapsed / duration;
			t = t * t * (3f - 2f * t);
			_panelRect.anchoredPosition = Vector2.Lerp(_startPos, _targetPos, t);
			yield return null;
		}
		_panelRect.anchoredPosition = _targetPos;
	}

	private IEnumerator LoadAudio()
	{
		if (_isLoading)
		{
			yield break;
		}
		_isLoading = true;
		_playlist.Clear();
		_trackNames.Clear();
		string musicFolder = Path.Combine(Paths.PluginPath, "PhonkRowingMusic");
		if (!Directory.Exists(musicFolder))
		{
			Directory.CreateDirectory(musicFolder);
		}
		string[] allFiles = Directory.GetFiles(musicFolder);
		string[] musicFiles = allFiles.Where((string f) => f.EndsWith(".ogg", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".mp3", StringComparison.OrdinalIgnoreCase) || f.EndsWith(".wav", StringComparison.OrdinalIgnoreCase)).ToArray();
		if (musicFiles.Length == 0)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("В папке " + musicFolder + " нет .ogg, .mp3 или .wav файлов!"));
			if ((Object)(object)_trackNameText != (Object)null)
			{
				_trackNameText.text = "Нет треков";
			}
			_isLoading = false;
			yield break;
		}
		string[] array = musicFiles;
		foreach (string file in array)
		{
			string url = "file://" + file;
			string ext = Path.GetExtension(file).ToLower();
			AudioType audioType = (AudioType)14;
			if (ext == ".mp3")
			{
				audioType = (AudioType)13;
			}
			else if (ext == ".wav")
			{
				audioType = (AudioType)20;
			}
			DownloadHandlerAudioClip handler = new DownloadHandlerAudioClip(url, audioType);
			handler.streamAudio = false;
			UnityWebRequest www = new UnityWebRequest(url, "GET", (DownloadHandler)(object)handler, (UploadHandler)null);
			try
			{
				yield return www.SendWebRequest();
				if ((int)www.result == 1)
				{
					AudioClip clip = handler.audioClip;
					string trackName = Path.GetFileNameWithoutExtension(file);
					_playlist.Add(clip);
					_trackNames.Add(trackName);
				}
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
			if (_playlist.Count % 3 == 0)
			{
				yield return null;
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"Загружено треков: {_playlist.Count}");
		if (_playlist.Count > 0)
		{
			if (_savedTime > 0f && _savedIndex < _playlist.Count)
			{
				_currentTrackIndex = _savedIndex;
				_audioSource.clip = _playlist[_currentTrackIndex];
				_audioSource.time = _savedTime;
				_savedTime = 0f;
			}
			else
			{
				_currentTrackIndex = 0;
				_audioSource.clip = _playlist[0];
			}
			UpdateUITrackName(force: true);
		}
		_isLoading = false;
	}

	private void ReloadPlaylist()
	{
		if (!_isLoading)
		{
			_savedTime = _audioSource.time;
			_savedIndex = _currentTrackIndex;
			_audioSource.Stop();
			_audioSource.clip = null;
			_isPausedByPlayer = true;
			if ((Object)(object)_trackNameText != (Object)null)
			{
				_trackNameText.text = "Загрузка...";
			}
			((MonoBehaviour)this).StartCoroutine(LoadAudio());
		}
	}

	private void RPC_PlayTrack(long sender, string trackName, float time)
	{
		_lastTrackName = trackName;
		_lastTrackStartTime = time;
		_lastRpcTime = Time.time;
		if (!_cachedIsOnShip)
		{
			return;
		}
		int num = _trackNames.IndexOf(trackName);
		if (num != -1)
		{
			if ((Object)(object)_audioSource.clip != (Object)(object)_playlist[num])
			{
				_currentTrackIndex = num;
				_audioSource.clip = _playlist[_currentTrackIndex];
				_audioSource.time = time;
			}
			_audioSource.UnPause();
			if (!_audioSource.isPlaying)
			{
				_audioSource.Play();
			}
			_isPausedByPlayer = false;
			UpdateUIButtonState();
			UpdateUITrackName(force: true);
		}
	}

	private void RPC_PauseTrack(long sender)
	{
		_lastTrackName = null;
		if (_audioSource.isPlaying)
		{
			_audioSource.Pause();
			_isPausedByPlayer = true;
			UpdateUIButtonState();
		}
	}

	private void RPC_StopTrack(long sender)
	{
		_lastTrackName = null;
		_audioSource.Stop();
		_audioSource.time = 0f;
		_isPausedByPlayer = true;
		UpdateUIButtonState();
	}

	private void TogglePlayPause()
	{
		if (_audioSource.isPlaying)
		{
			_audioSource.Pause();
			_isPausedByPlayer = true;
			ZRoutedRpc.instance.InvokeRoutedRPC(0L, "PhonkRowing_PauseTrack", Array.Empty<object>());
		}
		else
		{
			_audioSource.UnPause();
			if (!_audioSource.isPlaying)
			{
				_audioSource.Play();
			}
			_isPausedByPlayer = false;
			if (_playlist.Count > 0)
			{
				ZRoutedRpc.instance.InvokeRoutedRPC(0L, "PhonkRowing_PlayTrack", new object[2]
				{
					_trackNames[_currentTrackIndex],
					_audioSource.time
				});
			}
		}
		UpdateUIButtonState();
	}

	private void PlayNextTrackAndBroadcast()
	{
		if (_playlist.Count != 0)
		{
			_currentTrackIndex = (_currentTrackIndex + 1) % _playlist.Count;
			_audioSource.clip = _playlist[_currentTrackIndex];
			_audioSource.time = 0f;
			_audioSource.Play();
			_isPausedByPlayer = false;
			UpdateUIButtonState();
			UpdateUITrackName(force: true);
			ZRoutedRpc.instance.InvokeRoutedRPC(0L, "PhonkRowing_PlayTrack", new object[2]
			{
				_trackNames[_currentTrackIndex],
				0f
			});
		}
	}

	private void PreviousTrack()
	{
		if (_playlist.Count != 0)
		{
			_currentTrackIndex--;
			if (_currentTrackIndex < 0)
			{
				_currentTrackIndex = _playlist.Count - 1;
			}
			_audioSource.clip = _playlist[_currentTrackIndex];
			_audioSource.time = 0f;
			_audioSource.Play();
			_isPausedByPlayer = false;
			UpdateUIButtonState();
			UpdateUITrackName(force: true);
			ZRoutedRpc.instance.InvokeRoutedRPC(0L, "PhonkRowing_PlayTrack", new object[2]
			{
				_trackNames[_currentTrackIndex],
				0f
			});
		}
	}

	private void OpenMusicFolder()
	{
		string text = Path.Combine(Paths.PluginPath, "PhonkRowingMusic");
		if (Directory.Exists(text))
		{
			try
			{
				Process.Start("explorer.exe", text);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Не удалось открыть папку: " + ex.Message));
			}
		}
	}

	private void UpdateUITrackName(bool force = false)
	{
		if ((Object)(object)_trackNameText != (Object)null && _trackNames.Count > 0 && (force || _lastDisplayedTrackIndex != _currentTrackIndex))
		{
			_lastDisplayedTrackIndex = _currentTrackIndex;
			_trackNameText.text = "Играет: " + _trackNames[_currentTrackIndex];
		}
	}

	private void UpdateUIButtonState()
	{
		if ((Object)(object)_playPauseText != (Object)null)
		{
			_playPauseText.text = (_audioSource.isPlaying ? "||" : ">");
		}
	}

	private void CreatePlayerUI()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_018b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Expected O, but got Unknown
		//IL_0249: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_0353: Unknown result type (might be due to invalid IL or missing references)
		//IL_0364: Unknown result type (might be due to invalid IL or missing references)
		//IL_036a: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0401: Unknown result type (might be due to invalid IL or missing references)
		//IL_040b: Expected O, but got Unknown
		//IL_042c: Unknown result type (might be due to invalid IL or missing references)
		//IL_043b: Unknown result type (might be due to invalid IL or missing references)
		//IL_044a: Unknown result type (might be due to invalid IL or missing references)
		//IL_047a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0484: Expected O, but got Unknown
		//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_04fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0506: Expected O, but got Unknown
		//IL_0526: Unknown result type (might be due to invalid IL or missing references)
		//IL_0535: Unknown result type (might be due to invalid IL or missing references)
		//IL_0544: Unknown result type (might be due to invalid IL or missing references)
		//IL_056d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0577: Expected O, but got Unknown
		//IL_0593: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_05b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05be: Unknown result type (might be due to invalid IL or missing references)
		//IL_0602: Unknown result type (might be due to invalid IL or missing references)
		//IL_0611: Unknown result type (might be due to invalid IL or missing references)
		//IL_0620: Unknown result type (might be due to invalid IL or missing references)
		//IL_0649: Unknown result type (might be due to invalid IL or missing references)
		//IL_0653: Expected O, but got Unknown
		//IL_066f: Unknown result type (might be due to invalid IL or missing references)
		//IL_067e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0683: Unknown result type (might be due to invalid IL or missing references)
		//IL_0694: Unknown result type (might be due to invalid IL or missing references)
		//IL_069a: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_06cb: Expected O, but got Unknown
		//IL_06f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0710: Unknown result type (might be due to invalid IL or missing references)
		//IL_0727: Unknown result type (might be due to invalid IL or missing references)
		//IL_073e: Unknown result type (might be due to invalid IL or missing references)
		//IL_074e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0755: Expected O, but got Unknown
		//IL_0789: Unknown result type (might be due to invalid IL or missing references)
		//IL_079f: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_07b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_07d0: Expected O, but got Unknown
		//IL_07fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0811: Unknown result type (might be due to invalid IL or missing references)
		//IL_081e: Unknown result type (might be due to invalid IL or missing references)
		//IL_082e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0835: Expected O, but got Unknown
		//IL_0869: Unknown result type (might be due to invalid IL or missing references)
		//IL_087f: Unknown result type (might be due to invalid IL or missing references)
		//IL_088c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0899: Unknown result type (might be due to invalid IL or missing references)
		//IL_08a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_08b0: Expected O, but got Unknown
		//IL_08da: Unknown result type (might be due to invalid IL or missing references)
		//IL_08f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0908: Unknown result type (might be due to invalid IL or missing references)
		//IL_0918: Unknown result type (might be due to invalid IL or missing references)
		//IL_091f: Expected O, but got Unknown
		//IL_09a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_09c3: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)_playerPanel != (Object)null) && !((Object)(object)InventoryGui.instance == (Object)null))
		{
			_hudPanel = new GameObject("PhonkHudPanel");
			_hudPanel.transform.SetParent(GUIManager.CustomGUIFront.transform, false);
			RectTransform val = _hudPanel.AddComponent<RectTransform>();
			val.anchorMin = new Vector2(0.5f, 1f);
			val.anchorMax = new Vector2(0.5f, 1f);
			val.pivot = new Vector2(0.5f, 1f);
			val.anchoredPosition = new Vector2(0f, -80f);
			val.sizeDelta = new Vector2(800f, 40f);
			_hudText = GUIManager.Instance.CreateText("Загрузка...", _hudPanel.transform, new Vector2(0f, 0f), new Vector2(1f, 1f), Vector2.zero, GUIManager.Instance.AveriaSerifBold, 24, new Color(1f, 0.85f, 0.2f), true, Color.black, 800f, 40f, false).GetComponent<Text>();
			_hudText.alignment = (TextAnchor)4;
			_hudOutline = ((Component)_hudText).gameObject.AddComponent<Outline>();
			((Shadow)_hudOutline).effectColor = Color.red;
			((Shadow)_hudOutline).effectDistance = new Vector2(2f, 2f);
			_hudPanel.SetActive(false);
			((MonoBehaviour)this).StartCoroutine(BeatAnalysisCoroutine());
			_playerPanel = new GameObject("PhonkPlayerPanel");
			Transform parent = ((Component)InventoryGui.instance.m_playerGrid).transform.parent;
			if ((Object)(object)parent != (Object)null)
			{
				_playerPanel.transform.SetParent(parent, false);
			}
			else
			{
				_playerPanel.transform.SetParent(GUIManager.CustomGUIFront.transform, false);
			}
			_playerPanel.transform.SetAsLastSibling();
			_panelRect = _playerPanel.AddComponent<RectTransform>();
			_panelRect.anchorMin = new Vector2(0.5f, 0f);
			_panelRect.anchorMax = new Vector2(0.5f, 0f);
			_panelRect.pivot = new Vector2(0.5f, 1f);
			_panelRect.sizeDelta = new Vector2(480f, 150f);
			_panelRect.anchoredPosition = _startPos;
			Image val2 = _playerPanel.AddComponent<Image>();
			Sprite sprite = GUIManager.Instance.GetSprite("panel_bkg");
			if ((Object)(object)sprite != (Object)null)
			{
				val2.sprite = sprite;
				val2.type = (Type)1;
			}
			else
			{
				((Graphic)val2).color = new Color(0.15f, 0.1f, 0.05f, 0.9f);
			}
			GameObject val3 = GUIManager.Instance.CreateText("Загрузка...", _playerPanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 45f), GUIManager.Instance.AveriaSerifBold, 18, Color.white, true, Color.black, 450f, 30f, false);
			_trackNameText = val3.GetComponent<Text>();
			_trackNameText.alignment = (TextAnchor)4;
			GameObject val4 = GUIManager.Instance.CreateButton("<<", _playerPanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-125f, 5f), 40f, 40f);
			((UnityEvent)val4.GetComponent<Button>().onClick).AddListener(new UnityAction(PreviousTrack));
			_playPauseButton = GUIManager.Instance.CreateButton("||", _playerPanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-75f, 5f), 40f, 40f).GetComponent<Button>();
			((UnityEvent)_playPauseButton.onClick).AddListener(new UnityAction(TogglePlayPause));
			_playPauseText = ((Component)_playPauseButton).GetComponentInChildren<Text>();
			GameObject val5 = GUIManager.Instance.CreateButton(">>", _playerPanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-25f, 5f), 40f, 40f);
			((UnityEvent)val5.GetComponent<Button>().onClick).AddListener(new UnityAction(PlayNextTrackAndBroadcast));
			GameObject val6 = GUIManager.Instance.CreateButton("", _playerPanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(45f, 5f), 75f, 35f);
			((UnityEvent)val6.GetComponent<Button>().onClick).AddListener(new UnityAction(ReloadPlaylist));
			GameObject val7 = GUIManager.Instance.CreateText("Reload", val6.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, GUIManager.Instance.AveriaSerifBold, 13, Color.white, true, Color.black, 75f, 35f, false);
			val7.GetComponent<Text>().alignment = (TextAnchor)4;
			GameObject val8 = GUIManager.Instance.CreateButton("", _playerPanel.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(130f, 5f), 75f, 35f);
			((UnityEvent)val8.GetComponent<Button>().onClick).AddListener(new UnityAction(OpenMusicFolder));
			GameObject val9 = GUIManager.Instance.CreateText("Folder", val8.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), Vector2.zero, GUIManager.Instance.AveriaSerifBold, 13, Color.white, true, Color.black, 75f, 35f, false);
			val9.GetComponent<Text>().alignment = (TextAnchor)4;
			GameObject val10 = new GameObject("VolumeSlider");
			val10.transform.SetParent(_playerPanel.transform, false);
			RectTransform val11 = val10.AddComponent<RectTransform>();
			val11.anchorMin = new Vector2(0.5f, 0.5f);
			val11.anchorMax = new Vector2(0.5f, 0.5f);
			val11.anchoredPosition = new Vector2(0f, -45f);
			val11.sizeDelta = new Vector2(380f, 20f);
			GameObject val12 = new GameObject("Background");
			val12.transform.SetParent(val10.transform, false);
			Image val13 = val12.AddComponent<Image>();
			((Graphic)val13).color = new Color(0.15f, 0.15f, 0.15f, 0.8f);
			RectTransform component = val12.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.sizeDelta = Vector2.zero;
			GameObject val14 = new GameObject("Fill Area");
			val14.transform.SetParent(val10.transform, false);
			RectTransform val15 = val14.AddComponent<RectTransform>();
			val15.anchorMin = new Vector2(0f, 0.25f);
			val15.anchorMax = new Vector2(1f, 0.75f);
			val15.sizeDelta = Vector2.zero;
			GameObject val16 = new GameObject("Fill");
			val16.transform.SetParent(val14.transform, false);
			Image val17 = val16.AddComponent<Image>();
			((Graphic)val17).color = new Color(0.85f, 0.85f, 0.85f, 1f);
			RectTransform component2 = val16.GetComponent<RectTransform>();
			component2.anchorMin = Vector2.zero;
			component2.anchorMax = Vector2.one;
			component2.sizeDelta = Vector2.zero;
			GameObject val18 = new GameObject("Handle Slide Area");
			val18.transform.SetParent(val10.transform, false);
			RectTransform val19 = val18.AddComponent<RectTransform>();
			val19.anchorMin = new Vector2(0f, 0f);
			val19.anchorMax = new Vector2(1f, 1f);
			val19.sizeDelta = new Vector2(-20f, 0f);
			GameObject val20 = new GameObject("Handle");
			val20.transform.SetParent(val18.transform, false);
			Image val21 = val20.AddComponent<Image>();
			Sprite val22 = GUIManager.Instance.GetSprite("gui_slider_handle");
			if ((Object)(object)val22 == (Object)null)
			{
				val22 = GUIManager.Instance.GetSprite("slider_handle");
			}
			if ((Object)(object)val22 == (Object)null)
			{
				val22 = CreateCircleSprite();
			}
			val21.sprite = val22;
			((Graphic)val21).color = new Color(0.9f, 0.55f, 0.1f, 1f);
			RectTransform component3 = val20.GetComponent<RectTransform>();
			component3.sizeDelta = new Vector2(24f, 24f);
			Slider val23 = val10.AddComponent<Slider>();
			val23.fillRect = component2;
			val23.handleRect = component3;
			((Selectable)val23).targetGraphic = (Graphic)(object)val21;
			val23.direction = (Direction)0;
			val23.minValue = 0f;
			val23.maxValue = 1f;
			val23.value = _audioSource.volume;
			((UnityEvent<float>)(object)val23.onValueChanged).AddListener((UnityAction<float>)delegate(float num)
			{
				_audioSource.volume = num;
				_musicVolume.Value = num;
			});
			_volumeSlider = val23;
			_playerPanel.SetActive(false);
		}
	}

	private Sprite CreateCircleSprite()
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_000e: Expected O, but got Unknown
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		int num = 64;
		Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
		Color[] array = (Color[])(object)new Color[num * num];
		float num2 = (float)num / 2f;
		float num3 = (float)num / 2f;
		for (int i = 0; i < num; i++)
		{
			for (int j = 0; j < num; j++)
			{
				float num4 = Vector2.Distance(new Vector2((float)j, (float)i), new Vector2(num2, num2));
				array[i * num + j] = ((num4 <= num3) ? Color.white : Color.clear);
			}
		}
		val.SetPixels(array);
		val.Apply();
		return Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f));
	}

	private void OnDestroy()
	{
		if ((Object)(object)_playerPanel != (Object)null)
		{
			Object.Destroy((Object)(object)_playerPanel);
		}
		if ((Object)(object)_hudPanel != (Object)null)
		{
			Object.Destroy((Object)(object)_hudPanel);
		}
	}
}
[HarmonyPatch(typeof(InventoryGui), "Show")]
public static class InventoryShowPatch
{
	public static void Postfix()
	{
		if ((Object)(object)PhonkRowingPlugin.Instance != (Object)null)
		{
			PhonkRowingPlugin.Instance.IsInventoryOpen = true;
		}
	}
}
[HarmonyPatch(typeof(InventoryGui), "Hide")]
public static class InventoryHidePatch
{
	public static void Postfix()
	{
		if ((Object)(object)PhonkRowingPlugin.Instance != (Object)null)
		{
			PhonkRowingPlugin.Instance.IsInventoryOpen = false;
		}
	}
}
[HarmonyPatch(typeof(Menu), "Show")]
public static class MenuShowPatch
{
	public static void Postfix()
	{
		if ((Object)(object)PhonkRowingPlugin.Instance != (Object)null)
		{
			PhonkRowingPlugin.Instance.IsMenuOpen = true;
		}
	}
}
[HarmonyPatch(typeof(Menu), "Hide")]
public static class MenuHidePatch
{
	public static void Postfix()
	{
		if ((Object)(object)PhonkRowingPlugin.Instance != (Object)null)
		{
			PhonkRowingPlugin.Instance.IsMenuOpen = false;
		}
	}
}