Decompiled source of OdinOnDemand v1.0.8

OdinOnDemand.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AngleSharp.Text;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using JetBrains.Annotations;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OdinOnDemand.Components;
using OdinOnDemand.Dynamic;
using OdinOnDemand.Interfaces;
using OdinOnDemand.MPlayer;
using OdinOnDemand.Utils;
using OdinOnDemand.Utils.Config;
using OdinOnDemand.Utils.Net;
using OdinOnDemand.Utils.Net.Explode;
using OdinOnDemand.Utils.UI;
using SoundCloudExplode;
using SoundCloudExplode.Tracks;
using Steamworks;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.Serialization;
using UnityEngine.UI;
using UnityEngine.Video;
using YoutubeDLSharp;
using YoutubeDLSharp.Options;
using YoutubeExplode;
using YoutubeExplode.Common;
using YoutubeExplode.Playlists;
using YoutubeExplode.Videos;
using YoutubeExplode.Videos.Streams;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("OdinOnDemand")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ValMedia")]
[assembly: AssemblyProduct("")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.8")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.8.0")]
[module: UnverifiableCode]
namespace OdinOnDemand
{
	[BepInPlugin("com.valmedia.odinondemand", "OdinOnDemand", "1.0.8")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class OdinOnDemandPlugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.valmedia.odinondemand";

		public const string PluginName = "OdinOnDemand";

		public const string PluginVersion = "1.0.8";

		private static readonly CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

		public static readonly RpcHandler RPCHandlers = new RpcHandler();

		public static Material MainScreenMat;

		public static Dictionary<string, Sprite> UISprites;

		private AssetBundle _valMediaAssets;

		private static Harmony _harmony;

		private static string _pieceRecipeFile;

		private static string _itemRecipeFile;

		private static readonly string OdinConfigFolder = Paths.ConfigPath + "/OdinOnDemand/";

		public static ConfigFile OdinConfig { get; private set; } = new ConfigFile(OdinConfigFolder + "config.cfg", true);


		public StationManager StationManager { get; private set; }

		private void Awake()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Expected O, but got Unknown
			OODConfig.Bind(OdinConfig);
			_pieceRecipeFile = OdinConfigFolder + "/recipes.json";
			_itemRecipeFile = OdinConfigFolder + "/recipes_item.json";
			OODConfig.SyncManager();
			RPCHandlers.Create();
			GameObject val = new GameObject("OODStationMan");
			StationManager = val.AddComponent<StationManager>();
			Object.DontDestroyOnLoad((Object)(object)val);
			AddLocalizations();
			LoadAssets();
			PrefabManager.OnVanillaPrefabsAvailable += AddCartVariant;
			ConfigFile val2 = new ConfigFile(Path.Combine(OdinConfigFolder, "com.ood.valmedia.keyconfig.cfg"), true);
			SynchronizationManager.Instance.RegisterCustomConfig(val2);
			KeyConfig.SetupKeyConfig(val2);
			_harmony = new Harmony("Harmony.ValMedia.OOD");
			_harmony.PatchAll();
			Logger.LogDebug((object)"** OdinOnDemand Initialized **");
		}

		private static void AddCartVariant()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			PieceConfig val = new PieceConfig();
			val.Name = "Bard's Wagon";
			val.Description = "A mobile media player on wheels, controlled by a remote.";
			val.PieceTable = "Hammer";
			val.Category = "OOD";
			val.AddRequirement(new RequirementConfig("Wood", 26, 0, false));
			val.AddRequirement(new RequirementConfig("Bronze", 2, 0, false));
			val.AddRequirement(new RequirementConfig("BronzeNails", 14, 0, false));
			AssetBundle val2 = AssetUtils.LoadAssetBundleFromResources("videoplayers", typeof(OdinOnDemandPlugin).Assembly);
			GameObject val3 = val2.LoadAsset<GameObject>("assets/cartplayer_attach.prefab");
			val.Icon = val2.LoadAsset<Sprite>("assets/MOD ICONS/cartplayericon.png");
			if (PieceManager.Instance.AddPiece(new CustomPiece("cartplayer", "Cart", val)))
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab("cartplayer");
				Object.Instantiate<GameObject>(val3, prefab.transform, true);
				((Component)prefab.transform.Find("cartplayer_attach(Clone)")).gameObject.AddComponent<CartPlayerComponent>();
			}
			val2.Unload(false);
			PrefabManager.OnVanillaPrefabsAvailable -= AddCartVariant;
		}

		private void LoadAssets()
		{
			_valMediaAssets = AssetUtils.LoadAssetBundleFromResources("videoplayers", typeof(OdinOnDemandPlugin).Assembly);
			Logger.LogDebug((object)"Loading OdinOnDemand Assets");
			AddRecipes();
			MainScreenMat = _valMediaAssets.LoadAsset<Material>("assets/MOD MATS/screenmaterial.mat");
			UISprites = new Dictionary<string, Sprite>();
			string[] allAssetNames = _valMediaAssets.GetAllAssetNames();
			foreach (string text in allAssetNames)
			{
				if (text.Contains("modui"))
				{
					Sprite val = _valMediaAssets.LoadAsset<Sprite>(text);
					UISprites.Add(((Object)val).name, val);
				}
			}
			_valMediaAssets.Unload(false);
		}

		private void AddRecipes()
		{
			if (!File.Exists(_pieceRecipeFile))
			{
				WriteDefaultPieceConfig("default.json");
				Logger.LogDebug((object)("Did not find recipe json, loading and writing default recipes to: " + _pieceRecipeFile));
			}
			if (!File.Exists(_itemRecipeFile))
			{
				WriteDefaultItemConfig("default_items.json");
				Logger.LogDebug((object)("Did not find item recipe json, loading and writing default recipes to: " + _itemRecipeFile));
			}
			string text = File.ReadAllText(_pieceRecipeFile);
			if (!IsValidJson(text))
			{
				WriteDefaultPieceConfig("default.json");
				Logger.LogWarning((object)"JSON in com.ood.valmedia.recipes.json is invalid. Setting to default recipes. If you wish to edit recipes please use a JSON validator or delete your recipe file and restart the game for a new default file.");
			}
			string text2 = File.ReadAllText(_itemRecipeFile);
			if (!IsValidJson(text2))
			{
				WriteDefaultItemConfig("default_items.json");
				Logger.LogWarning((object)"JSON in com.ood.valmedia.recipes_item.json is invalid. Setting to default recipes. If you wish to edit recipes please use a JSON validator or delete your recipe file and restart the game for a new default file.");
			}
			if ((!text.Contains("receiver") || !text.Contains("theater") || !text.Contains("speaker")) && OODConfig.AutoUpdateRecipes.Value)
			{
				Logger.LogDebug((object)"Old recipe file detected. Updating to new recipes.");
				List<PieceConfig> oldRecipes = PieceConfig.ListFromJson(text);
				string newRecipes = FileFromManifest("OdinOnDemand.Assets.default.json");
				UpdateRecipeFile(newRecipes, oldRecipes, _pieceRecipeFile);
			}
			else if (!OODConfig.AutoUpdateRecipes.Value)
			{
				Logger.LogWarning((object)"Auto recipe update disabled. Skipping recipe update.");
			}
			LoadPieceConfigList(PieceConfig.ListFromJson(text));
			LoadItemConfigList(ItemConfig.ListFromJson(text2));
		}

		private void UpdateRecipeFile(string newRecipes, List<PieceConfig> oldRecipes, string file)
		{
			if (newRecipes != "")
			{
				List<PieceConfig> recipesToMerge = PieceConfig.ListFromJson(newRecipes);
				MergeRecipes(oldRecipes, recipesToMerge);
				try
				{
					List<PieceConfigDTO> list = PieceConfigDTO.ToDTOList(oldRecipes);
					string contents = JsonConvert.SerializeObject((object)list, (Formatting)1);
					File.WriteAllText(file, contents);
					return;
				}
				catch (Exception ex)
				{
					Logger.LogError((object)"Failed to write new recipes to file. Check log for details.");
					Logger.LogWarning((object)ex);
					return;
				}
			}
			Logger.LogError((object)"FATAL Failed to load default recipes.");
		}

		private static void MergeRecipes(List<PieceConfig> mergeRecipe, List<PieceConfig> recipesToMerge)
		{
			foreach (PieceConfig newRecipe in recipesToMerge)
			{
				if (!mergeRecipe.Any((PieceConfig r) => r.Name == newRecipe.Name))
				{
					mergeRecipe.Add(newRecipe);
				}
			}
		}

		private void WriteDefaultPieceConfig(string fileName)
		{
			try
			{
				string pieceRecipeFile = _pieceRecipeFile;
				string value = FileFromManifest("OdinOnDemand.Assets." + fileName);
				StreamWriter streamWriter = File.CreateText(pieceRecipeFile);
				streamWriter.Write(value);
				streamWriter.Close();
				streamWriter.Dispose();
			}
			catch (Exception ex)
			{
				Logger.LogError((object)"Exception when handling default recipe file. Check log for details.");
				Logger.LogWarning((object)ex);
			}
		}

		private void WriteDefaultItemConfig(string fileName)
		{
			try
			{
				string itemRecipeFile = _itemRecipeFile;
				string value = FileFromManifest("OdinOnDemand.Assets." + fileName);
				StreamWriter streamWriter = File.CreateText(itemRecipeFile);
				streamWriter.Write(value);
				streamWriter.Close();
				streamWriter.Dispose();
			}
			catch (Exception ex)
			{
				Logger.LogError((object)"Exception when handling default recipe file. Check log for details.");
				Logger.LogWarning((object)ex);
			}
		}

		private static string FileFromManifest(string file)
		{
			string result = "";
			using Stream stream = typeof(OdinOnDemandPlugin).Assembly.GetManifestResourceStream(file);
			if (stream != null)
			{
				using StreamReader streamReader = new StreamReader(stream);
				result = streamReader.ReadToEnd();
			}
			return result;
		}

		private void LoadPieceConfigList(List<PieceConfig> pieceConfigs)
		{
			pieceConfigs.ForEach(delegate(PieceConfig c)
			{
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_009a: Expected O, but got Unknown
				string text = LocalizationManager.Instance.TryTranslate(c.Name).ToLower().Replace(" ", "")
					.Replace("'", "");
				Texture2D val = _valMediaAssets.LoadAsset<Texture2D>("assets/MOD ICONS/" + text + "icon.png");
				Sprite icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), Vector2.zero);
				c.Icon = icon;
				PieceManager.Instance.AddPiece(new CustomPiece(_valMediaAssets, text, false, c));
			});
		}

		private void LoadItemConfigList(List<ItemConfig> itemConfigs)
		{
			itemConfigs.ForEach(delegate(ItemConfig c)
			{
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Expected O, but got Unknown
				string text = LocalizationManager.Instance.TryTranslate(c.Name).ToLower().Replace(" ", "")
					.Replace("'", "");
				((BaseUnityPlugin)this).Logger.LogDebug((object)("Adding item: " + text));
				ItemManager.Instance.AddItem(new CustomItem(_valMediaAssets, text, false, c));
			});
		}

		private void AddLocalizations()
		{
			CustomLocalization localization = Localization;
			string text = "English";
			localization.AddTranslation(ref text, new Dictionary<string, string>
			{
				{ "piece_flatscreen", "Flatscreen" },
				{ "piece_tabletv", "Table TV" },
				{ "piece_boombox", "Boombox" },
				{ "piece_oldtv", "Old TV" },
				{ "piece_laptop", "Laptop" },
				{ "piece_monitor", "Monitor" },
				{ "piece_gramophone", "Gramophone" },
				{ "piece_theaterscreen", "Theater Screen" },
				{ "piece_receiver", "Receiver" },
				{ "piece_studiospeaker", "Studio Speaker" },
				{ "piece_radio", "Radio" },
				{ "piece_standingspeaker", "Standing Speaker" },
				{ "item_remote", "Remote Control" },
				{ "item_skaldsgirdle", "Skald's Girdle" },
				{ "remote_usehint", "Use Screen" },
				{ "remote_linkhint", "Link/Unlink" },
				{ "skaldsgirdle_hint", "Consult Skald" },
				{ "remote_changelinkmodehint", "Change Link Mode" },
				{ "item_remote_description", "Allows you to use media-players from a distance." },
				{ "item_skaldsgirdle_description", "Allows you to commune with Skald while traveling." }
			});
		}

		private static bool IsValidJson(string strInput)
		{
			//IL_0061: Expected O, but got Unknown
			if (string.IsNullOrWhiteSpace(strInput))
			{
				return false;
			}
			strInput = strInput.Trim();
			if ((strInput.StartsWith("{") && strInput.EndsWith("}")) || (strInput.StartsWith("[") && strInput.EndsWith("]")))
			{
				try
				{
					JToken val = JToken.Parse(strInput);
					return true;
				}
				catch (JsonReaderException val2)
				{
					JsonReaderException val3 = val2;
					Logger.LogWarning((object)((Exception)(object)val3).Message);
					return false;
				}
				catch (Exception ex)
				{
					Logger.LogWarning((object)ex.ToString());
					return false;
				}
			}
			return false;
		}
	}
}
namespace OdinOnDemand.MPlayer
{
	public abstract class BasePlayer : MonoBehaviour, IPlayer
	{
		internal HashSet<SpeakerComponent> mSpeakers = new HashSet<SpeakerComponent>();

		private Transform centerAudioSphere;

		protected SphereCollider triggerCollider;

		public VideoPlayer mScreen { get; set; }

		public AudioSource mAudio { get; set; }

		public Piece mPiece { get; internal set; }

		public Animator Animator { get; set; }

		protected GameObject ScreenPlaneObj { get; set; }

		protected internal GameObject ScreenUICanvasObj { get; set; }

		protected GameObject RadioPanelObj { get; set; }

		protected Coroutine DynamicStationCoroutine { get; set; }

		protected internal GameObject LoadingCircleObj { get; set; }

		protected Material TargetTexMat { get; set; }

		public string mName { get; set; }

		public string MediaPlayerID { get; set; }

		public string UnparsedURL { get; set; }

		public Uri DownloadURL { get; set; }

		public Uri YoutubeSoundDirectUri { get; set; }

		public Uri YoutubeVideoDirectUri { get; set; }

		public int PlaylistPosition { get; set; }

		public string PlaylistString { get; set; }

		public List<VideoInfo> CurrentPlaylist { get; set; }

		public List<VideoInfo> PreShufflePlaylist { get; set; }

		public string PlaylistURL { get; set; }

		public PlayerSettings PlayerSettings { get; set; }

		public UIController UIController { get; set; }

		protected static AudioFader AudioFaderComp { get; set; }

		protected ParticleSystem WaveParticleSystem { get; set; }

		public URLGrab URLGrab { get; set; }

		public DLSharp Ytdl { get; set; }

		public RpcHandler RPC { get; set; }

		public ZNetView ZNetView { get; set; }

		private string YoutubeURLNode { get; set; }

		public void Awake()
		{
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Expected O, but got Unknown
			ComponentLists.MediaComponentLists[((object)this).GetType()].Add(this);
			UIController = new UIController(this);
			PlayerSettings = new PlayerSettings();
			ZNetView = ((Component)this).GetComponent<ZNetView>();
			UIController.Initialize();
			RPC = OdinOnDemandPlugin.RPCHandlers;
			URLGrab = new URLGrab();
			ZNetView = ((Component)this).gameObject.GetComponentInParent<ZNetView>();
			mScreen = ((Component)this).gameObject.GetComponentInChildren<VideoPlayer>();
			mScreen.prepareCompleted += new EventHandler(ScreenPrepareCompleted);
			mScreen.loopPointReached += new EventHandler(EndReached);
			SetupAudio();
			((MonoBehaviour)this).InvokeRepeating("UpdateLoadingIndicator", 0.5f, 0.5f);
			((MonoBehaviour)this).InvokeRepeating("UpdateChecks", 1f, 1f);
			((MonoBehaviour)this).InvokeRepeating("SyncTime", OODConfig.SyncTime.Value + 30f, OODConfig.SyncTime.Value);
			Ytdl = ((Component)this).gameObject.AddComponent<DLSharp>();
			((MonoBehaviour)this).StartCoroutine(Ytdl.Setup());
			ZDO zDO = ZNetView.GetZDO();
			if (Object.op_Implicit((Object)(object)ZNetScene.instance) && zDO != null)
			{
				if (!zDO.GetString("MediaPlayerID", "").Equals(""))
				{
					RequestOwnership(zDO);
					string text = GenerateUniqueID();
					zDO.Set("MediaPlayerID", text);
					SendUpdateZDO_RPC();
				}
				MediaPlayerID = zDO.GetString("MediaPlayerID", "");
			}
			if (OODConfig.AudioFadeType.Value != OODConfig.FadeType.None && (Object)(object)AudioFader.Instance == (Object)null && (Object)(object)GameObject.Find("OODAudioFader") == (Object)null)
			{
				GameObject val = new GameObject("OODAudioFader");
				AudioFaderComp = val.AddComponent<AudioFader>();
				Object.DontDestroyOnLoad((Object)(object)val);
			}
		}

		public void OnDestroy()
		{
			ComponentLists.RemoveComponent(((object)this).GetType(), this);
		}

		private void EndReached(VideoPlayer source)
		{
			if (PlayerSettings.IsPlayingPlaylist)
			{
				if (PlaylistPosition < CurrentPlaylist.Count() - 1)
				{
					PlaylistPosition++;
					SetURL(CurrentPlaylist.ElementAt(PlaylistPosition).Url);
				}
				else if (PlayerSettings.IsLooping)
				{
					PlaylistPosition = 0;
					SetURL(CurrentPlaylist.ElementAt(PlaylistPosition).Url);
				}
			}
			if (PlayerSettings.PlayerType == CinemaPackage.MediaPlayers.Radio && Object.op_Implicit((Object)(object)Animator) && (!mScreen.isLooping || !mAudio.loop) && !PlayerSettings.IsPlayingPlaylist)
			{
				Animator.SetBool(PlayerSettings.Playing, false);
			}
			bool isPlaying = mScreen.isPlaying;
			PlayerSettings.IsPlaying = isPlaying;
		}

		private void ScreenPrepareCompleted(VideoPlayer source)
		{
			if (PlayerSettings.PlayerType == CinemaPackage.MediaPlayers.CinemaScreen && Object.op_Implicit((Object)(object)ScreenPlaneObj))
			{
				ScreenPlaneObj.SetActive(true);
			}
			if (Object.op_Implicit((Object)(object)WaveParticleSystem) && OODConfig.MobilePlayerVisuals.Value)
			{
				WaveParticleSystem.Play();
			}
			if (Object.op_Implicit((Object)(object)UIController.LoadingIndicatorObj))
			{
				UIController.LoadingIndicatorObj.SetActive(false);
			}
			if (Object.op_Implicit((Object)(object)ScreenUICanvasObj) && Object.op_Implicit((Object)(object)LoadingCircleObj))
			{
				ScreenUICanvasObj.SetActive(false);
				LoadingCircleObj.SetActive(false);
			}
			float timeZDO = GetTimeZDO();
			UpdatePlayerTime(timeZDO);
			((MonoBehaviour)this).StartCoroutine(DelayedExecution(0.5f, SendRequestTimeSync_RPC));
			if (!PlayerSettings.IsPaused)
			{
				if (Object.op_Implicit((Object)(object)Animator))
				{
					Animator.SetBool(PlayerSettings.Playing, true);
				}
				if (Object.op_Implicit((Object)(object)WaveParticleSystem) && OODConfig.MobilePlayerVisuals.Value)
				{
					WaveParticleSystem.Play();
				}
				PlayerSettings.IsPlaying = true;
				PlayerSettings.IsPaused = false;
				source.Play();
				mAudio.Play();
			}
			else
			{
				PlayerSettings.IsPlaying = true;
				PlayerSettings.IsPaused = true;
				source.Pause();
				mAudio.Pause();
			}
		}

		private void UpdateChecks()
		{
			float num = default(float);
			mAudio.outputAudioMixerGroup.audioMixer.GetFloat("MasterVolume", ref num);
			if (PlayerSettings.PlayerType == CinemaPackage.MediaPlayers.CinemaScreen)
			{
				if (num != OODConfig.MasterVolumeScreen.Value)
				{
					mAudio.outputAudioMixerGroup.audioMixer.SetFloat("MasterVolume", OODConfig.MasterVolumeScreen.Value);
				}
			}
			else if (PlayerSettings.PlayerType == CinemaPackage.MediaPlayers.BeltPlayer || PlayerSettings.PlayerType == CinemaPackage.MediaPlayers.CartPlayer)
			{
				if (num != OODConfig.MasterVolumeTransport.Value)
				{
					mAudio.outputAudioMixerGroup.audioMixer.SetFloat("MasterVolume", OODConfig.MasterVolumeTransport.Value);
				}
			}
			else if (num != OODConfig.MasterVolumeMusicplayer.Value)
			{
				mAudio.outputAudioMixerGroup.audioMixer.SetFloat("MasterVolume", OODConfig.MasterVolumeMusicplayer.Value);
			}
			if (Object.op_Implicit((Object)(object)UIController.URLPanelObj))
			{
				if (PlayerSettings.IsPlayingPlaylist)
				{
					UIController.UpdatePlaylistUI();
					UIController.PlaylistTrackText.text = PlaylistString;
				}
				else
				{
					UIController.UpdatePlaylistUI();
				}
			}
			if (!mAudio.isPlaying && mAudio.time == 0f && !mAudio.loop && (Object)(object)Animator != (Object)null)
			{
				Animator.SetBool(PlayerSettings.Playing, false);
			}
			if (Object.op_Implicit((Object)(object)triggerCollider) && triggerCollider.radius != mAudio.maxDistance)
			{
				triggerCollider.radius = mAudio.maxDistance;
			}
		}

		public void SetURL(string url)
		{
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			Encoding uTF = Encoding.UTF8;
			byte[] bytes = uTF.GetBytes(url);
			url = uTF.GetString(bytes);
			UnparsedURL = url;
			mAudio.clip = null;
			if (UnparsedURL == "")
			{
				Stop(isRPC: true);
			}
			else
			{
				if (!Object.op_Implicit((Object)(object)((IPlayer)this).mScreen) && !Object.op_Implicit((Object)(object)mAudio))
				{
					return;
				}
				if (url.Contains("youtube.com/watch?v=") || url.Contains("youtube.com/shorts/") || url.Contains("youtu.be") || url.Contains("youtube.com/playlist"))
				{
					UIController.UpdatePlaylistInfo();
					if (url.Contains("?list=") || url.Contains("&list="))
					{
						SetPlaylist(UnparsedURL);
						return;
					}
				}
				mScreen.time = 0.0;
				mAudio.time = 0f;
				PlayerSettings.IsPaused = false;
				PlayerSettings.IsPlaying = true;
				RPC.SendData(0L, CinemaPackage.RPCDataType.SetVideoUrl, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position, 0f, UnparsedURL, CinemaPackage.PlayerStatus.Playing);
				SaveZDO();
			}
		}

		private void SetPlaylist(string url)
		{
			((MonoBehaviour)this).StartCoroutine(URLGrab.GetYouTubePlaylistCoroutine(url, delegate(List<VideoInfo> videoInfos)
			{
				if (videoInfos != null)
				{
					CurrentPlaylist = videoInfos;
					PlayerSettings.IsPlayingPlaylist = true;
					PlaylistPosition = 0;
					if (OODConfig.DebugEnabled.Value)
					{
						Logger.LogDebug((object)"Playlist info");
						Logger.LogDebug((object)("Count: " + CurrentPlaylist.Count));
						Logger.LogDebug((object)CurrentPlaylist.ToString());
						Logger.LogDebug((object)("Playing first url of " + CurrentPlaylist.ElementAt(PlaylistPosition).Url));
					}
					PlaylistURL = url;
					SetURL(CurrentPlaylist.ElementAt(PlaylistPosition).Url);
					if (Object.op_Implicit((Object)(object)UIController.URLPanelObj))
					{
						UIController.UpdatePlaylistUI();
						UIController.ToggleShuffleObj.GetComponentInChildren<Text>().text = "N";
						UIController.ToggleShuffleObj.SetActive(true);
						UIController.ToggleShuffleTextObj.SetActive(true);
					}
				}
				else
				{
					Logger.LogError((object)"Failed to load playlist");
				}
			}));
		}

		public void Play(bool isRPC = false)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			if (PlayerSettings.CurrentMode == PlayerSettings.PlayerMode.Dynamic)
			{
				if (PlayerSettings.DynamicStation != null)
				{
					RPC.SendData(0L, CinemaPackage.RPCDataType.RequestStation, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position, 0f, PlayerSettings.DynamicStation.Title);
				}
				return;
			}
			if (!isRPC)
			{
				RPC.SendData(0L, CinemaPackage.RPCDataType.Play, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position, GetTime());
				PlayerSettings.IsPlaying = true;
				PlayerSettings.IsPaused = false;
				SaveZDO();
				return;
			}
			if (PlayerSettings.PlayerType == CinemaPackage.MediaPlayers.CinemaScreen)
			{
				ScreenPlaneObj.SetActive(true);
			}
			if (PlayerSettings.PlayerLinkType == PlayerSettings.LinkType.Youtube || PlayerSettings.PlayerLinkType == PlayerSettings.LinkType.RelativeVideo || PlayerSettings.PlayerLinkType == PlayerSettings.LinkType.Video)
			{
				mScreen.Play();
				PlayerSettings.IsPlaying = mScreen.isPlaying;
				PlayerSettings.IsPaused = mScreen.isPaused;
				if (Object.op_Implicit((Object)(object)Animator))
				{
					Animator.SetBool(PlayerSettings.Playing, true);
				}
				if (Object.op_Implicit((Object)(object)WaveParticleSystem) && OODConfig.MobilePlayerVisuals.Value && (mScreen.isPlaying || mScreen.isPrepared || mAudio.isPlaying))
				{
					WaveParticleSystem.Play();
				}
			}
			else if (PlayerSettings.PlayerLinkType == PlayerSettings.LinkType.Audio)
			{
				if (Object.op_Implicit((Object)(object)Animator))
				{
					Animator.SetBool(PlayerSettings.Playing, true);
				}
				if (Object.op_Implicit((Object)(object)WaveParticleSystem) && OODConfig.MobilePlayerVisuals.Value)
				{
					WaveParticleSystem.Play();
				}
				if (PlayerSettings.IsPaused && (Object)(object)mAudio.clip != (Object)null)
				{
					mAudio.UnPause();
				}
				else
				{
					mAudio.Play();
				}
				bool isPlaying = mAudio.isPlaying;
				PlayerSettings.IsPaused = !isPlaying;
				PlayerSettings.IsPlaying = isPlaying;
			}
		}

		public void PlayStation(string stationName)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			DynamicStation station = StationManager.Instance.GetStation(stationName);
			PlayerSettings.DynamicStation = station;
			PlayerSettings.IsPlaying = true;
			PlayerSettings.IsPaused = false;
			PlayerSettings.CurrentMode = PlayerSettings.PlayerMode.Dynamic;
			UnparsedURL = PlayerSettings.DynamicStation.Title;
			RPC.SendData(0L, CinemaPackage.RPCDataType.RequestStation, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position, 0f, stationName);
			SaveZDO();
		}

		public void RPC_PlayStation(string dataURL, string trackTitle, float time)
		{
			DynamicStation station = StationManager.Instance.GetStation(dataURL);
			Track track = station?.Tracks.FirstOrDefault((Track x) => x.Title == trackTitle);
			if (track != null)
			{
				station.CurrentTrackIndex = station.Tracks.IndexOf(track);
				station.Tracks[station.CurrentTrackIndex].CurrentTime = time;
				PlayerSettings.CurrentMode = PlayerSettings.PlayerMode.Dynamic;
				PlayerSettings.DynamicStation = station;
				PlayerSettings.IsPlaying = true;
				PlayerSettings.IsPaused = false;
				InitiateDynamicStationPlayback();
				((MonoBehaviour)this).StartCoroutine(DelayedExecution(2f, SendRequestTimeSync_RPC));
			}
		}

		private void InitiateDynamicStationPlayback()
		{
			PlayerSettings.PlayerLinkType = PlayerSettings.LinkType.Audio;
			Track track = PlayerSettings.DynamicStation.Tracks[PlayerSettings.DynamicStation.CurrentTrackIndex];
			mAudio.clip = track.AudioClip;
			mAudio.time = track.CurrentTime;
			foreach (KeyValuePair<Type, IList> mediaComponentList in ComponentLists.MediaComponentLists)
			{
				foreach (BasePlayer item in mediaComponentList.Value)
				{
					if (!((Object)(object)item == (Object)(object)this) && Object.op_Implicit((Object)(object)item) && item.PlayerSettings.DynamicStation != null && item.PlayerSettings.CurrentMode == PlayerSettings.PlayerMode.Dynamic && item.PlayerSettings.DynamicStation.Title == PlayerSettings.DynamicStation.Title && item.PlayerSettings.IsPlaying && !item.PlayerSettings.IsPaused)
					{
						item.mAudio.clip = track.AudioClip;
						item.mAudio.time = track.CurrentTime;
					}
				}
			}
			mAudio.Play();
			PlayerSettings.IsPlaying = true;
			PlayerSettings.IsPaused = false;
			PlayerSettings.IsPlayingPlaylist = false;
			PlayerSettings.PlayerLinkType = PlayerSettings.LinkType.Audio;
			PlayerSettings.CurrentMode = PlayerSettings.PlayerMode.Dynamic;
			UnparsedURL = PlayerSettings.DynamicStation.Title;
			float time = track.AudioClip.length - mAudio.time;
			if (DynamicStationCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(DynamicStationCoroutine);
			}
			DynamicStationCoroutine = ((MonoBehaviour)this).StartCoroutine(AudioEndEvent(time, PlayNextDynamicStationTrack));
			if (Object.op_Implicit((Object)(object)WaveParticleSystem))
			{
				WaveParticleSystem.Play();
			}
			if (Object.op_Implicit((Object)(object)Animator))
			{
				Animator.SetBool(PlayerSettings.Playing, true);
			}
			UpdateRadioPanel();
		}

		private void PlayNextDynamicStationTrack()
		{
			if (PlayerSettings.DynamicStation != null)
			{
				mAudio.Stop();
				mAudio.clip = null;
				mAudio.time = 0f;
				((MonoBehaviour)this).StartCoroutine(DelayedExecution(0.35f, delegate
				{
					//IL_002a: Unknown result type (might be due to invalid IL or missing references)
					RPC.SendData(0L, CinemaPackage.RPCDataType.RequestStation, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position, 0f, PlayerSettings.DynamicStation.Title);
					((MonoBehaviour)this).StartCoroutine(DelayedExecution(2f, SendRequestTimeSync_RPC));
				}));
			}
		}

		private IEnumerator AudioEndEvent(float time, Action method)
		{
			yield return (object)new WaitForSeconds(time);
			method?.Invoke();
		}

		public void UpdateRadioPanel()
		{
			if (Object.op_Implicit((Object)(object)RadioPanelObj) && Object.op_Implicit((Object)(object)UIController.RadioPanelThumbnail) && mAudio.isPlaying)
			{
				if (Object.op_Implicit((Object)(object)ScreenUICanvasObj))
				{
					ScreenUICanvasObj.SetActive(true);
				}
				if (Object.op_Implicit((Object)(object)ScreenPlaneObj))
				{
					ScreenPlaneObj.SetActive(true);
				}
				ClearRenderTexture(mScreen.targetTexture);
				if (PlayerSettings.DynamicStation != null && PlayerSettings.CurrentMode == PlayerSettings.PlayerMode.Dynamic)
				{
					RadioPanelObj.SetActive(true);
					UIController.RadioPanelThumbnail.sprite = (((Object)(object)PlayerSettings.DynamicStation.Thumbnail != (Object)null) ? PlayerSettings.DynamicStation.Thumbnail : null);
				}
				else if (mAudio.isPlaying && PlayerSettings.PlayerLinkType == PlayerSettings.LinkType.Audio)
				{
					RadioPanelObj.SetActive(true);
					UIController.RadioPanelThumbnail.sprite = (((Object)(object)PlayerSettings.Thumbnail != (Object)null) ? PlayerSettings.Thumbnail : null);
				}
				else if (PlayerSettings.PlayerLinkType != PlayerSettings.LinkType.Audio)
				{
					RadioPanelObj.SetActive(false);
				}
			}
		}

		public void Pause(bool isRPC = false)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (!isRPC)
			{
				RPC.SendData(0L, CinemaPackage.RPCDataType.Pause, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position, GetTime());
				PlayerSettings.IsPaused = true;
				SaveZDO();
				return;
			}
			if (Object.op_Implicit((Object)(object)Animator))
			{
				Animator.SetBool(PlayerSettings.Playing, false);
			}
			if (Object.op_Implicit((Object)(object)WaveParticleSystem))
			{
				WaveParticleSystem.Stop();
			}
			mScreen.Pause();
			mAudio.Pause();
			PlayerSettings.IsPaused = true;
		}

		private void SetupAudio()
		{
			centerAudioSphere = ((Component)this).transform.Find("audio/centerSphere");
			mAudio = ((Component)this).gameObject.GetComponentInChildren<AudioSource>();
			mAudio.maxDistance = OODConfig.DefaultDistance.Value;
			PlayerSettings.Volume = OODConfig.DefaultAudioSourceVolume.Value;
			mAudio.spatialBlend = 1f;
			mAudio.spatialize = true;
			mAudio.spatializePostEffects = true;
			mAudio.volume = PlayerSettings.Volume;
		}

		protected void SetupRadioPanel()
		{
			if (Object.op_Implicit((Object)(object)RadioPanelObj))
			{
				UIController.RadioPanelThumbnail = ((Component)RadioPanelObj.transform.Find("thumbnail")).GetComponent<Image>();
			}
			if (Object.op_Implicit((Object)(object)ScreenUICanvasObj))
			{
				Transform val = ScreenUICanvasObj.transform.Find("mainCanvas/radioPanel/waveformPanel");
				if (Object.op_Implicit((Object)(object)val))
				{
					AudioWaveformVisualizer audioWaveformVisualizer = ((Component)val).gameObject.AddComponent<AudioWaveformVisualizer>();
					audioWaveformVisualizer.Setup(mAudio);
				}
			}
			if (Object.op_Implicit((Object)(object)UIController.RadioPanelThumbnail))
			{
				if (PlayerSettings.DynamicStation != null && PlayerSettings.CurrentMode == PlayerSettings.PlayerMode.Dynamic)
				{
					UIController.RadioPanelThumbnail.sprite = PlayerSettings.DynamicStation.Thumbnail;
				}
				if ((Object)(object)PlayerSettings.Thumbnail != (Object)null)
				{
					UIController.RadioPanelThumbnail.sprite = PlayerSettings.Thumbnail;
				}
				else
				{
					UIController.RadioPanelThumbnail.sprite = null;
				}
			}
		}

		protected void UpdateLoadingIndicator()
		{
			if (URLGrab.LoadingBool && !string.IsNullOrEmpty(UnparsedURL))
			{
				if (Object.op_Implicit((Object)(object)ScreenUICanvasObj) && Object.op_Implicit((Object)(object)LoadingCircleObj) && Object.op_Implicit((Object)(object)RadioPanelObj))
				{
					ScreenUICanvasObj.SetActive(true);
					RadioPanelObj.SetActive(false);
					LoadingCircleObj.SetActive(true);
				}
				UIController?.SetLoadingIndicatorActive(active: true);
				int num = PlayerSettings.LoadingCount % 4;
				if (UIController != null && (Object)(object)UIController.LoadingIndicatorObj != (Object)null)
				{
					UIController.LoadingIndicatorObj.GetComponent<Text>().text = UIController.LoadingMessages[num];
				}
				PlayerSettings.LoadingCount++;
			}
			else if (!URLGrab.LoadingBool && Object.op_Implicit((Object)(object)UIController.LoadingIndicatorObj) && UIController.LoadingIndicatorObj.activeSelf)
			{
				UIController.SetLoadingIndicatorActive(active: false);
			}
		}

		public void Stop(bool isRPC = false)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			if (!isRPC)
			{
				RPC.SendData(0L, CinemaPackage.RPCDataType.Stop, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position, GetTime());
				return;
			}
			if (DynamicStationCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(DynamicStationCoroutine);
			}
			PlayerSettings.DynamicStation = null;
			mScreen.Stop();
			mAudio.Stop();
			mScreen.url = "";
			mAudio.clip = null;
			mScreen.time = 0.0;
			mAudio.time = 0f;
			if (PlayerSettings.PlayerType == CinemaPackage.MediaPlayers.CinemaScreen)
			{
				ScreenPlaneObj.SetActive(false);
				if (Object.op_Implicit((Object)(object)ScreenUICanvasObj) && Object.op_Implicit((Object)(object)LoadingCircleObj))
				{
					ScreenUICanvasObj.SetActive(false);
					LoadingCircleObj.SetActive(false);
				}
			}
			if (Object.op_Implicit((Object)(object)Animator))
			{
				Animator.SetBool(PlayerSettings.Playing, false);
			}
			if (Object.op_Implicit((Object)(object)WaveParticleSystem))
			{
				WaveParticleSystem.Stop();
			}
			PlayerSettings.IsPlayingPlaylist = false;
			PlayerSettings.IsPlaying = false;
			PlayerSettings.IsPaused = false;
			CurrentPlaylist = null;
			URLGrab.Reset();
			ClearRenderTexture(mScreen.targetTexture);
			UnparsedURL = null;
			DownloadURL = null;
			YoutubeURLNode = null;
			YoutubeSoundDirectUri = null;
			YoutubeVideoDirectUri = null;
			PlaylistURL = null;
			PlaylistString = null;
			PlaylistPosition = 0;
			UIController.SetInputFieldText("");
			UIController.UpdatePlaylistUI();
			SaveZDO();
			SendUpdateZDO_RPC();
		}

		protected IEnumerator AudioWebRequest(Uri url)
		{
			DownloadHandlerAudioClip dh = new DownloadHandlerAudioClip(url, (AudioType)13)
			{
				compressed = false
			};
			UnityWebRequest wr = new UnityWebRequest(url, "GET", (DownloadHandler)(object)dh, (UploadHandler)null);
			try
			{
				yield return wr.SendWebRequest();
				if ((int)wr.result == 3 || (int)wr.result == 2)
				{
					Logger.LogError((object)wr.error);
					yield break;
				}
				mAudio.clip = dh.audioClip;
				mScreen.url = "";
				mScreen.Stop();
				mAudio.Play();
				((MonoBehaviour)this).StartCoroutine(DelayedExecution(0.5f, SendRequestTimeSync_RPC));
				PlayerSettings.PlayerLinkType = PlayerSettings.LinkType.Audio;
				PlayerSettings.IsPlaying = true;
				PlayerSettings.IsPaused = false;
				if (Object.op_Implicit((Object)(object)Animator))
				{
					Animator.SetBool(PlayerSettings.Playing, true);
				}
				if (Object.op_Implicit((Object)(object)WaveParticleSystem) && OODConfig.MobilePlayerVisuals.Value)
				{
					WaveParticleSystem.Play();
				}
				if (Object.op_Implicit((Object)(object)ScreenUICanvasObj))
				{
					ScreenUICanvasObj.SetActive(true);
				}
				UpdateRadioPanel();
				UIController.ResetLoadingIndicator();
			}
			finally
			{
				((IDisposable)wr)?.Dispose();
			}
		}

		private IEnumerator CreateThumbnailFromURL(Uri url)
		{
			DownloadHandlerTexture dh = new DownloadHandlerTexture(true);
			UnityWebRequest wr = new UnityWebRequest(url, "GET", (DownloadHandler)(object)dh, (UploadHandler)null);
			try
			{
				yield return wr.SendWebRequest();
				if ((int)wr.result == 3 || (int)wr.result == 2)
				{
					Logger.LogError((object)("Error downloading image: " + wr.error));
					yield break;
				}
				Texture2D texture = DownloadHandlerTexture.GetContent(wr);
				Rect rect = new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height);
				Vector2 pivot = new Vector2(0.5f, 0.5f);
				Sprite sprite = Sprite.Create(texture, rect, pivot);
				PlayerSettings.Thumbnail = sprite;
			}
			finally
			{
				((IDisposable)wr)?.Dispose();
			}
		}

		public void PlaySoundcloud(string sentUrl, bool isRPC)
		{
			Uri url = URLGrab.CleanUrl(sentUrl);
			UIController.SetLoadingIndicatorText("Processing");
			UIController.SetLoadingIndicatorActive(active: true);
			if (sentUrl != null)
			{
				((MonoBehaviour)this).StartCoroutine(URLGrab.GetSoundcloudExplodeCoroutine(url, delegate(Uri resultUrl, Uri artworkUri)
				{
					if (resultUrl != null)
					{
						if (artworkUri != null)
						{
							((MonoBehaviour)this).StartCoroutine(CreateThumbnailFromURL(artworkUri));
						}
						else
						{
							PlayerSettings.Thumbnail = null;
						}
						((MonoBehaviour)this).StartCoroutine(AudioWebRequest(resultUrl));
					}
					else
					{
						UIController.SetLoadingIndicatorText("Null, check logs");
						Logger.LogWarning((object)"Failed to load Soundcloud");
						((MonoBehaviour)this).StartCoroutine(ResetLoadingIndicatorAfterDelay());
					}
				}));
			}
			else
			{
				string message = "Soundcloud Null";
				Logger.LogInfo((object)"Soundcloud Null, check for exceptions");
				((MonoBehaviour)this).StartCoroutine(UIController.UnavailableIndicator(message));
			}
		}

		public void PlayYoutube(string url)
		{
			if (URLGrab.LoadingBool)
			{
				return;
			}
			if (OODConfig.IsYtEnabled.Value)
			{
				if (PlayerSettings.IsLooping)
				{
					mScreen.isLooping = true;
					mAudio.loop = true;
				}
				if (OODConfig.YoutubeAPI.Value == OODConfig.YouTubeAPI.YouTubeExplode)
				{
					StartYoutubeProcessing(url);
					return;
				}
				YoutubeURLNode = url;
				((MonoBehaviour)this).StartCoroutine(YoutubeNodeQuery());
			}
			else
			{
				((MonoBehaviour)this).StartCoroutine(UIController.UnavailableIndicator("YouTube disabled"));
			}
		}

		public void RPC_SetURL(string url, bool isPaused = false, float time = 0f)
		{
			if (url == null)
			{
				return;
			}
			Encoding uTF = Encoding.UTF8;
			byte[] bytes = uTF.GetBytes(url);
			url = uTF.GetString(bytes);
			PlayerSettings.IsPaused = isPaused;
			ClearRenderTexture(mScreen.targetTexture);
			if (URLGrab.IsAudioFile(url))
			{
				string relativeURL = URLGrab.GetRelativeURL(url);
				if (relativeURL != "")
				{
					url = relativeURL;
					PlayerSettings.PlayerLinkType = PlayerSettings.LinkType.RelativeAudio;
				}
				else
				{
					PlayerSettings.PlayerLinkType = PlayerSettings.LinkType.Audio;
				}
				DownloadURL = URLGrab.CleanUrl(url);
				((MonoBehaviour)this).StartCoroutine(AudioWebRequest(DownloadURL));
			}
			else if (url.Contains("soundcloud.com/"))
			{
				PlayerSettings.PlayerLinkType = PlayerSettings.LinkType.Soundcloud;
				PlaySoundcloud(url, isRPC: true);
			}
			else
			{
				if (!url.Contains("\\") && !url.Contains(".") && !url.Contains("/"))
				{
					return;
				}
				string relativeURL2 = URLGrab.GetRelativeURL(url);
				if (relativeURL2 != "")
				{
					mScreen.url = relativeURL2;
					PlayerSettings.PlayerLinkType = PlayerSettings.LinkType.RelativeVideo;
					if (OODConfig.DebugEnabled.Value)
					{
						Logger.LogDebug((object)("Playing: " + relativeURL2));
					}
					BeginLoadingPrepare();
				}
				if ((url.StartsWith("http://") || url.StartsWith("https://")) && !Path.HasExtension(url) && OODConfig.IsYtEnabled.Value)
				{
					if (PlayerSettings.IsLooping && (!mScreen.isLooping || !mAudio.loop))
					{
						mScreen.isLooping = true;
						mAudio.loop = true;
					}
					PlayerSettings.PlayerLinkType = PlayerSettings.LinkType.Youtube;
					PlayYoutube(url);
				}
				else
				{
					PlayerSettings.PlayerLinkType = PlayerSettings.LinkType.Video;
					mScreen.url = url;
					BeginLoadingPrepare();
					if (OODConfig.DebugEnabled.Value)
					{
						Logger.LogDebug((object)("Playing: " + url));
					}
				}
			}
		}

		private void BeginLoadingPrepare()
		{
			mScreen.Prepare();
			ClearRenderTexture(mScreen.targetTexture);
			if (Object.op_Implicit((Object)(object)ScreenUICanvasObj) && Object.op_Implicit((Object)(object)LoadingCircleObj))
			{
				ScreenUICanvasObj.SetActive(true);
				LoadingCircleObj.SetActive(true);
			}
		}

		public void StartYoutubeProcessing(string url)
		{
			if (Object.op_Implicit((Object)(object)UIController.LoadingIndicatorObj))
			{
				UIController.SetLoadingIndicatorText("Processing");
				UIController.LoadingIndicatorObj.SetActive(true);
			}
			((MonoBehaviour)this).StartCoroutine(Ytdl.GetVideoUrlWithRetry(url, delegate(string resultUrl)
			{
				if (!string.IsNullOrEmpty(resultUrl))
				{
					Logger.LogDebug((object)("Result URL: " + resultUrl));
					mScreen.url = resultUrl;
					BeginLoadingPrepare();
				}
				else
				{
					Logger.LogError((object)"Failed to get video URL");
					UIController.SetLoadingIndicatorText("Failed to load video");
					Logger.LogWarning((object)"Failed to load video");
					((MonoBehaviour)this).StartCoroutine(ResetLoadingIndicatorAfterDelay());
				}
			}));
		}

		private IEnumerator ResetLoadingIndicatorAfterDelay()
		{
			yield return (object)new WaitForSeconds(1.75f);
			UIController.ResetLoadingIndicator();
		}

		private IEnumerator YoutubeNodeQuery(bool isRPC = false)
		{
			if (YoutubeURLNode == null)
			{
				Logger.LogDebug((object)"nodejs: error in yt query, youtube url null. are you sure you want use nodejs?");
				yield break;
			}
			string url = Uri.EscapeDataString(YoutubeURLNode);
			string nodeUrl = OODConfig.NodeUrl.Value;
			string authCode = OODConfig.YtAuthCode.Value;
			UnityWebRequest www = UnityWebRequest.Get(nodeUrl + url + "/" + authCode);
			www.timeout = 30;
			UIController.SetLoadingIndicatorText("Processing");
			UIController.LoadingIndicatorObj.SetActive(true);
			yield return www.SendWebRequest();
			if ((int)www.result != 1)
			{
				Debug.Log((object)www.error);
				UIController.LoadingIndicatorObj.GetComponent<Text>().text = www.error;
				yield return (object)new WaitForSeconds(2f);
				UIController.LoadingIndicatorObj.SetActive(false);
			}
			else if (www.downloadHandler.text.Contains("AUTH DENIED"))
			{
				UIController.SetLoadingIndicatorText("Invalid Auth");
				yield return (object)new WaitForSeconds(2f);
				UIController.LoadingIndicatorObj.SetActive(false);
			}
			else if (www.downloadHandler.text.Contains("\\"))
			{
				string[] lines = www.downloadHandler.text.Split(new string[4] { "\r\n", "\r", "\n", "\\n" }, StringSplitOptions.None);
				for (int i = 0; i < lines.Length; i++)
				{
					lines[i] = lines[i].Replace("\"", "");
				}
				if (Uri.TryCreate(lines[0], UriKind.Absolute, out Uri cleanVideoUri2))
				{
					YoutubeVideoDirectUri = cleanVideoUri2;
				}
				else
				{
					Logger.LogError((object)("Invalid URI: " + lines[0]));
					UIController.SetLoadingIndicatorText("Invalid URI");
					yield return (object)new WaitForSeconds(2f);
					UIController.LoadingIndicatorObj.SetActive(false);
				}
				if (Uri.TryCreate(lines[1], UriKind.Absolute, out Uri cleanSoundUri))
				{
					YoutubeSoundDirectUri = cleanSoundUri;
				}
				else
				{
					Logger.LogError((object)("Invalid URI: " + lines[1]));
					UIController.SetLoadingIndicatorText("Invalid URI");
					yield return (object)new WaitForSeconds(2f);
					UIController.LoadingIndicatorObj.SetActive(false);
				}
				((MonoBehaviour)this).StartCoroutine(CreateYoutubeAudioAndPlay());
			}
			else
			{
				string cleanUrl = www.downloadHandler.text.Replace("\"", "");
				if (Uri.TryCreate(cleanUrl, UriKind.Absolute, out Uri cleanVideoUri))
				{
					YoutubeVideoDirectUri = cleanVideoUri;
				}
				else
				{
					Logger.LogError((object)("Invalid URI: " + cleanUrl));
					UIController.SetLoadingIndicatorText("Invalid URI");
					yield return (object)new WaitForSeconds(2f);
					UIController.LoadingIndicatorObj.SetActive(false);
				}
				mScreen.url = YoutubeVideoDirectUri.AbsoluteUri;
				mScreen.Prepare();
				if (Object.op_Implicit((Object)(object)ScreenUICanvasObj) && Object.op_Implicit((Object)(object)LoadingCircleObj))
				{
					ScreenUICanvasObj.SetActive(true);
					LoadingCircleObj.SetActive(true);
				}
				UIController.LoadingIndicatorObj.SetActive(false);
			}
		}

		private IEnumerator CreateYoutubeAudioAndPlay()
		{
			if (YoutubeSoundDirectUri == null)
			{
				Logger.LogDebug((object)"sound url is null, waiting");
				yield return (object)new WaitForSeconds(1f);
			}
			if (YoutubeSoundDirectUri == null)
			{
				Logger.LogDebug((object)"sound url is null still, exiting");
				yield break;
			}
			DownloadHandlerAudioClip dh = new DownloadHandlerAudioClip(YoutubeSoundDirectUri, (AudioType)0)
			{
				compressed = true
			};
			UnityWebRequest wr = new UnityWebRequest(YoutubeSoundDirectUri, "GET", (DownloadHandler)(object)dh, (UploadHandler)null);
			try
			{
				yield return wr.SendWebRequest();
				if ((int)wr.result == 3 || (int)wr.result == 2)
				{
					Logger.LogWarning((object)wr.error);
					UIController.LoadingIndicatorObj.SetActive(false);
					yield break;
				}
				mAudio.clip = dh.audioClip;
				if (YoutubeVideoDirectUri != null)
				{
					mScreen.url = YoutubeVideoDirectUri.AbsoluteUri;
					mScreen.Prepare();
					if (Object.op_Implicit((Object)(object)ScreenUICanvasObj) && Object.op_Implicit((Object)(object)LoadingCircleObj))
					{
						ScreenUICanvasObj.SetActive(true);
						LoadingCircleObj.SetActive(true);
					}
					UIController.LoadingIndicatorObj.SetActive(false);
				}
				else
				{
					Logger.LogDebug((object)"nodejs: yt url is null. are you sure want to use nodejs?");
					UIController.LoadingIndicatorObj.SetActive(false);
				}
			}
			finally
			{
				((IDisposable)wr)?.Dispose();
			}
		}

		public void UpdatePlayerTime(float time)
		{
			if (Math.Abs(mScreen.time - (double)time) > 0.05)
			{
				mScreen.time = time;
			}
			if ((double)Math.Abs(mAudio.time - time) > 0.05)
			{
				mAudio.time = time;
			}
		}

		public void SetLock(bool locked)
		{
			PlayerSettings.IsLocked = locked;
			if (Object.op_Implicit((Object)(object)UIController.URLPanelObj))
			{
				if (PlayerSettings.IsLocked)
				{
					UIController.LockedIconObj.SetActive(true);
					UIController.UnlockedIconObj.SetActive(false);
				}
				else
				{
					UIController.LockedIconObj.SetActive(false);
					UIController.UnlockedIconObj.SetActive(true);
				}
			}
		}

		public void SetDynamicStation(DynamicStation station)
		{
			PlayerSettings.DynamicStation = station;
		}

		public virtual void SaveZDO(bool saveTime = true)
		{
			ZDO zDO = ZNetView.GetZDO();
			if (zDO != null && !((Object)(object)mAudio == (Object)null))
			{
				RequestOwnership(zDO);
				zDO.Set("distance", mAudio.maxDistance);
				zDO.Set("adminOnly", PlayerSettings.AdminOnly);
				zDO.Set("isLooping", PlayerSettings.IsLooping);
				zDO.Set("isLocked", PlayerSettings.IsLocked);
				zDO.Set("isPlaying", PlayerSettings.IsPlaying);
				zDO.Set("isPaused", PlayerSettings.IsPaused);
				zDO.Set("currentMode", (int)PlayerSettings.CurrentMode);
				zDO.Set("url", UnparsedURL ?? "");
				if (saveTime)
				{
					SaveTimeZDO();
				}
				zDO.Set("speakers", SpeakerHelper.CompressSpeakerList(mSpeakers));
				zDO.Set("speakerCount", mSpeakers.Count);
			}
		}

		public void SaveTimeZDO()
		{
			ZDO zDO = ZNetView.GetZDO();
			if (zDO != null)
			{
				if (mScreen.isPlaying)
				{
					zDO.Set("time", (float)mScreen.time);
				}
				if (mAudio.isPlaying)
				{
					zDO.Set("time", mAudio.time);
				}
			}
		}

		public virtual void LoadZDO()
		{
			ZDO zDO = ZNetView.GetZDO();
			if (zDO == null)
			{
				return;
			}
			PlayerSettings.AdminOnly = zDO.GetBool("adminOnly", false);
			float @float = zDO.GetFloat("distance", 0f);
			if (@float != 0f)
			{
				mAudio.maxDistance = @float;
			}
			PlayerSettings.IsLocked = zDO.GetBool("isLocked", false);
			UnparsedURL = zDO.GetString("url", "");
			PlayerSettings.IsLooping = zDO.GetBool("isLooping", false);
			mAudio.loop = PlayerSettings.IsLooping;
			mScreen.isLooping = PlayerSettings.IsLooping;
			mSpeakers = SpeakerHelper.DecompressSpeakerList(zDO.GetByteArray("speakers", (byte[])null));
			UpdateSpeakerCenter();
			PlayerSettings.IsPlaying = zDO.GetBool("isPlaying", false);
			PlayerSettings.IsPaused = zDO.GetBool("isPaused", false);
			PlayerSettings.CurrentMode = (PlayerSettings.PlayerMode)zDO.GetInt("currentMode", 0);
			if (PlayerSettings.CurrentMode == PlayerSettings.PlayerMode.Dynamic)
			{
				PlayerSettings.DynamicStation = StationManager.Instance.GetStation(UnparsedURL);
				if (PlayerSettings.DynamicStation != null)
				{
					((MonoBehaviour)this).StartCoroutine(DelayedExecution(1f, delegate
					{
						//IL_002a: Unknown result type (might be due to invalid IL or missing references)
						RPC.SendData(0L, CinemaPackage.RPCDataType.RequestStation, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position, 0f, PlayerSettings.DynamicStation.Title);
					}));
					((MonoBehaviour)this).StartCoroutine(DelayedExecution(2f, SendRequestTimeSync_RPC));
				}
			}
			else
			{
				((MonoBehaviour)this).StartCoroutine(DelayedExecution(3f, delegate
				{
					RPC_SetURL(UnparsedURL, PlayerSettings.IsPaused);
				}));
			}
		}

		public virtual void UpdateZDO()
		{
			ZDO zDO = ZNetView.GetZDO();
			if (zDO == null)
			{
				return;
			}
			PlayerSettings.AdminOnly = zDO.GetBool("adminOnly", false);
			float @float = zDO.GetFloat("distance", 0f);
			if (@float != 0f)
			{
				mAudio.maxDistance = @float;
			}
			PlayerSettings.IsLocked = zDO.GetBool("isLocked", false);
			PlayerSettings.IsLooping = zDO.GetBool("isLooping", false);
			mAudio.loop = PlayerSettings.IsLooping;
			mScreen.isLooping = PlayerSettings.IsLooping;
			PlayerSettings.CurrentMode = (PlayerSettings.PlayerMode)zDO.GetInt("currentMode", 0);
			if (zDO.GetString("url", "") != UnparsedURL)
			{
				if (string.IsNullOrEmpty(UnparsedURL))
				{
					if (PlayerSettings.CurrentMode == PlayerSettings.PlayerMode.Dynamic)
					{
						((MonoBehaviour)this).StartCoroutine(DelayedExecution(1f, delegate
						{
							//IL_0066: Unknown result type (might be due to invalid IL or missing references)
							PlayerSettings.DynamicStation = StationManager.Instance.GetStation(UnparsedURL);
							if (PlayerSettings.DynamicStation?.Title != null)
							{
								RPC.SendData(0L, CinemaPackage.RPCDataType.RequestStation, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position, 0f, PlayerSettings.DynamicStation.Title);
							}
						}));
						((MonoBehaviour)this).StartCoroutine(DelayedExecution(2f, SendRequestTimeSync_RPC));
					}
					else
					{
						RPC_SetURL(UnparsedURL);
					}
				}
				else
				{
					Stop(isRPC: true);
				}
			}
			if (zDO.GetInt("speakerCount", 0) != mSpeakers.Count)
			{
				mSpeakers = SpeakerHelper.DecompressSpeakerList(zDO.GetByteArray("speakers", (byte[])null));
				UpdateSpeakerCenter();
			}
			mSpeakers = SpeakerHelper.DecompressSpeakerList(zDO.GetByteArray("speakers", (byte[])null));
			UpdateSpeakerCenter();
			if (zDO.GetBool("isPaused", false) != PlayerSettings.IsPaused)
			{
				Pause(isRPC: true);
			}
		}

		public async void RPC_UpdateZDO()
		{
			await Task.Delay(350);
			UpdateZDO();
		}

		private IEnumerator DelayedExecution(float delay, Action action)
		{
			yield return (object)new WaitForSeconds(delay);
			action();
		}

		internal void SendUpdateZDO_RPC()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			RPC.SendData(0L, CinemaPackage.RPCDataType.UpdateZDO, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position, GetTime());
		}

		private void SyncTime()
		{
			if (mScreen.isPlaying || mAudio.isPlaying)
			{
				BroadcastTime();
			}
		}

		internal void SendRequestTimeSync_RPC()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			ZDO zDO = ZNetView.GetZDO();
			if (zDO != null && (!zDO.IsOwner() || PlayerSettings.CurrentMode == PlayerSettings.PlayerMode.Dynamic))
			{
				RPC.SendData(0L, CinemaPackage.RPCDataType.RequestTime, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position, 0f, UnparsedURL);
			}
		}

		public void BroadcastTime()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			ZDO zDO = ZNetView.GetZDO();
			if (zDO != null && zDO.IsOwner())
			{
				SaveTimeZDO();
				RPC.SendData(0L, CinemaPackage.RPCDataType.SyncTime, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position, GetTime());
			}
		}

		private string GenerateUniqueID()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			string[] obj = new string[5]
			{
				Path.GetRandomFileName().Replace(".", ""),
				"-",
				DateTime.Now.Ticks.ToString(),
				"-",
				null
			};
			ZDOID zDOID = ((Character)Player.m_localPlayer).GetZDOID();
			obj[4] = ((ZDOID)(ref zDOID)).UserID.ToString();
			return string.Concat(obj);
		}

		public Coroutine StartPlayerCoroutine(IEnumerator routine)
		{
			return ((MonoBehaviour)this).StartCoroutine(routine);
		}

		public void StopPlayerCoroutine(Coroutine routine)
		{
			((MonoBehaviour)this).StopCoroutine(routine);
		}

		public void ClaimOwnership(ZDO zdo)
		{
			if (zdo != null && !zdo.IsOwner())
			{
				zdo.SetOwner(ZDOMan.GetSessionID());
			}
		}

		public void SetOwnership(long peer)
		{
			ZDO zDO = ZNetView.GetZDO();
			if (zDO != null && zDO.IsOwner())
			{
				BroadcastTime();
				zDO.SetOwner(peer);
			}
		}

		public void RequestOwnership(ZDO zdo)
		{
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			if (zdo == null || zdo.IsOwner())
			{
				return;
			}
			Player val = ((IEnumerable<Player>)Player.s_players).FirstOrDefault((Func<Player, bool>)delegate(Player p)
			{
				//IL_0025: 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)
				int result;
				if ((Object)(object)p != (Object)null && (Object)(object)((Character)p).m_nview != (Object)null && ((Character)p).m_nview.IsValid())
				{
					ZDOID zDOID = ((Character)p).GetZDOID();
					result = ((((ZDOID)(ref zDOID)).UserID == zdo.GetOwner()) ? 1 : 0);
				}
				else
				{
					result = 0;
				}
				return (byte)result != 0;
			});
			if ((Object)(object)val == (Object)null)
			{
				ClaimOwnership(zdo);
			}
			else
			{
				RPC.SendData(0L, CinemaPackage.RPCDataType.RequestOwnership, PlayerSettings.PlayerType, MediaPlayerID, ((Component)this).gameObject.transform.position);
			}
		}

		public bool AddSpeaker(SpeakerComponent sp)
		{
			if (mSpeakers.Add(sp))
			{
				SaveZDO();
				UpdateSpeakerCenter();
				((MonoBehaviour)this).StartCoroutine(ShowCenterSphere());
				SendUpdateZDO_RPC();
				return true;
			}
			return false;
		}

		public void RemoveSpeaker(SpeakerComponent sp)
		{
			if (mSpeakers.Remove(sp))
			{
				SaveZDO();
				UpdateSpeakerCenter();
				((MonoBehaviour)this).StartCoroutine(ShowCenterSphere());
				SendUpdateZDO_RPC();
			}
		}

		private void UpdateSpeakerCenter()
		{
			//IL_003d: 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)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (mSpeakers.Count == 0)
			{
				((Component)mAudio).transform.position = ((Component)this).transform.position;
				return;
			}
			Vector3 position = SpeakerHelper.CalculateAudioCenter(mSpeakers.ToList());
			((Component)mAudio).transform.position = position;
		}

		public void UnlinkAllSpeakers()
		{
			mSpeakers.Clear();
			UIController.UpdateSpeakerCount();
			UpdateSpeakerCenter();
			((MonoBehaviour)this).StartCoroutine(ShowCenterSphere());
			SaveZDO();
			SendUpdateZDO_RPC();
		}

		private IEnumerator ShowCenterSphere()
		{
			if (Object.op_Implicit((Object)(object)centerAudioSphere))
			{
				((Component)centerAudioSphere).gameObject.SetActive(true);
				yield return (object)new WaitForSeconds(1f);
				((Component)centerAudioSphere).gameObject.SetActive(false);
			}
		}

		private float GetTime()
		{
			if (PlayerSettings.PlayerLinkType == PlayerSettings.LinkType.Youtube || PlayerSettings.PlayerLinkType == PlayerSettings.LinkType.RelativeVideo || PlayerSettings.PlayerLinkType == PlayerSettings.LinkType.Video)
			{
				return (float)mScreen.time;
			}
			if (PlayerSettings.PlayerLinkType == PlayerSettings.LinkType.Audio)
			{
				return mAudio.time;
			}
			return 0f;
		}

		private float GetTimeZDO()
		{
			ZDO zDO = ZNetView.GetZDO();
			if (zDO != null)
			{
				return zDO.GetFloat("time", 0f);
			}
			return 0f;
		}

		private void ClearRenderTexture(RenderTexture renderTexture)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(1, 1);
			val.SetPixel(0, 0, Color.black);
			val.Apply();
			RenderTexture active = RenderTexture.active;
			RenderTexture.active = renderTexture;
			Graphics.Blit((Texture)(object)val, renderTexture);
			RenderTexture.active = active;
			Object.Destroy((Object)(object)val);
		}

		GameObject IPlayer.get_gameObject()
		{
			return ((Component)this).gameObject;
		}
	}
	public class PlayerSettings
	{
		public enum LinkType
		{
			Youtube,
			Soundcloud,
			Video,
			Audio,
			RelativeAudio,
			RelativeVideo
		}

		public enum PlayerMode
		{
			URL,
			Dynamic
		}

		public static readonly int Playing = Animator.StringToHash("Playing");

		public static readonly int MainTex = Shader.PropertyToID("_MainTex");

		public static readonly int EmissiveColorMap = Shader.PropertyToID("_EmissiveColorMap");

		internal LinkType PlayerLinkType;

		public PlayerMode CurrentMode = PlayerMode.URL;

		public List<AudioClip> CurrentDynamicList = new List<AudioClip>();

		public bool IsPaused { get; set; }

		public bool IsPlaying { get; set; }

		public int LoadingCount { get; set; }

		public bool IsGuiActive { get; set; }

		public bool AdminOnly { get; set; }

		public bool IsLocked { get; set; } = true;


		public bool IsLooping { get; set; }

		public bool IsPlayingPlaylist { get; set; }

		public bool IsSettingsGuiActive { get; set; }

		public bool IsShuffling { get; set; }

		public float MuteVol { get; set; } = 0.5f;


		public float VerticalDistanceDropoff { get; set; } = 0f;


		public float DropoffPower { get; set; } = 1.5f;


		public float Volume { get; set; } = 0.5f;


		public bool IsLinkedToParent { get; set; } = false;


		public CinemaPackage.MediaPlayers PlayerType { get; set; }

		public DynamicStation DynamicStation { get; set; }

		public Sprite Thumbnail { get; set; }
	}
}
namespace OdinOnDemand.Patches
{
	[HarmonyPatch(typeof(Trader), "GetAvailableItems")]
	public class HaldorCustomPatch
	{
		private static void Postfix(ref List<TradeItem> __result)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			List<TradeItem> list = new List<TradeItem>();
			if (OODConfig.SkaldsGirdleEnabled.Value)
			{
				GameObject prefab = PrefabManager.Instance.GetPrefab("skaldsgirdle");
				if ((Object)(object)prefab != (Object)null)
				{
					list.Add(new TradeItem
					{
						m_prefab = prefab.GetComponent<ItemDrop>(),
						m_stack = 1,
						m_price = OODConfig.SkaldsGirdleCost.Value
					});
				}
			}
			__result = __result.Concat(list).ToList();
		}
	}
	public class PlacePiecePatch
	{
		[HarmonyPatch(typeof(Player), "PlacePiece", new Type[]
		{
			typeof(Piece),
			typeof(Vector3),
			typeof(Quaternion),
			typeof(bool)
		})]
		private static class PlacePiece_Patch
		{
			private static bool Prefix(Piece piece, Vector3 pos, Quaternion rot, bool doAttack = true)
			{
				//IL_002b: 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)
				if (StringExtensions.Contains(Pieces, ((Object)((Component)piece).gameObject).name, StringComparison.Ordinal) && OODConfig.VipMode.Value)
				{
					CSteamID steamID = SteamUser.GetSteamID();
					RankSystem.PlayerRank rank = RankSystem.GetRank(((object)(CSteamID)(ref steamID)).ToString());
					if (rank != RankSystem.PlayerRank.Admin && rank != RankSystem.PlayerRank.Vip)
					{
						RankSystem.DisplayBlockMenu();
						return false;
					}
				}
				return true;
			}
		}

		private static readonly string[] Pieces = new string[9] { "flatscreen", "theaterscreen", "tabletv", "monitor", "oldtv", "laptop", "radio", "boombox", "gramophone" };
	}
	[HarmonyPatch(typeof(Player), "RemovePiece")]
	public class RemovePiecePatch
	{
		private static readonly string[] Pieces = new string[9] { "flatscreen", "theaterscreen", "tabletv", "monitor", "oldtv", "laptop", "radio", "boombox", "gramophone" };

		[HarmonyPrefix]
		public static bool PrefixRemovePiece(ref Player __instance)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			if (!OODConfig.VipMode.Value)
			{
				return true;
			}
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(((Component)GameCamera.instance).transform.position, ((Component)GameCamera.instance).transform.forward, ref val, 50f, __instance.m_removeRayMask) || (double)Vector3.Distance(((RaycastHit)(ref val)).point, ((Character)__instance).m_eye.position) >= (double)__instance.m_maxPlaceDistance)
			{
				return false;
			}
			Piece componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<Piece>();
			if (!Object.op_Implicit((Object)(object)componentInParent) || !componentInParent.m_canBeRemoved)
			{
				return false;
			}
			if (StringExtensions.Contains(Pieces, ((Object)((Component)componentInParent).gameObject).name.Replace("(Clone)", ""), StringComparison.Ordinal) && OODConfig.VipMode.Value)
			{
				CSteamID steamID = SteamUser.GetSteamID();
				RankSystem.PlayerRank rank = RankSystem.GetRank(((object)(CSteamID)(ref steamID)).ToString());
				if (rank != RankSystem.PlayerRank.Admin && rank != RankSystem.PlayerRank.Vip)
				{
					RankSystem.DisplayBlockMenu();
					return false;
				}
			}
			return true;
		}
	}
}
namespace OdinOnDemand.Utils
{
	public class AudioFader : MonoBehaviour
	{
		private static MusicMan _musicMan;

		public static AudioFader Instance { get; set; }

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			else
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		public AudioFader()
		{
			_musicMan = MusicMan.m_instance;
		}

		public void Update()
		{
			if (OODConfig.AudioFadeType.Value == OODConfig.FadeType.Fade)
			{
				FadeGameMusic();
			}
		}

		public void FadeGameMusic()
		{
			var (num, basePlayer) = GetDistanceFromMediaplayers();
			if ((Object)(object)basePlayer == (Object)null)
			{
				_musicMan.m_musicVolume = PlayerPrefs.GetFloat("MusicVolume", 1f);
				return;
			}
			float num2 = basePlayer.mAudio.maxDistance / 1.35f;
			if (num > num2)
			{
				_musicMan.m_musicVolume = PlayerPrefs.GetFloat("MusicVolume", 1f);
				return;
			}
			float num3 = Mathf.Clamp01(num / num2);
			float num4 = 20f * Mathf.Log10(_musicMan.m_musicSource.volume);
			float num5 = Mathf.Lerp(OODConfig.LowestVolumeDB.Value, num4, num3);
			_musicMan.m_musicSource.volume = Mathf.Pow(10f, num5 / 20f);
		}

		private static (float, BasePlayer) GetDistanceFromMediaplayers()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)Player.m_localPlayer))
			{
				return (float.MaxValue, null);
			}
			Vector3 position = ((Component)Player.m_localPlayer).transform.position;
			float num = float.MaxValue;
			BasePlayer item = null;
			foreach (KeyValuePair<Type, IList> mediaComponentList in ComponentLists.MediaComponentLists)
			{
				foreach (BasePlayer item2 in mediaComponentList.Value)
				{
					if (Object.op_Implicit((Object)(object)item2) && (item2.mAudio.isPlaying || item2.mAudio.time != 0f || item2.mAudio.loop) && !item2.PlayerSettings.IsPaused && item2.PlayerSettings.IsPlaying)
					{
						Vector3 position2 = ((Component)item2).transform.position;
						float num2 = Vector3.Distance(position, position2);
						if (num2 < num)
						{
							num = num2;
							item = item2;
						}
					}
				}
			}
			return (num, item);
		}
	}
	public class RankSystem : MonoBehaviour
	{
		public enum PlayerRank
		{
			Player,
			Vip,
			Admin
		}

		private class CoroutineManager : MonoBehaviour
		{
		}

		private static GameObject _blockedText;

		private static CoroutineManager _coroutineManager;

		private static Coroutine _blockMenuCoroutine;

		public static PlayerRank GetRank(string steam)
		{
			if (ZNet.instance.ListContainsId(ZNet.instance.m_adminList, steam))
			{
				return PlayerRank.Admin;
			}
			if (OODConfig.VipList.Value.Contains(steam))
			{
				return PlayerRank.Vip;
			}
			return PlayerRank.Player;
		}

		private static void CreateBlockMenu()
		{
			//IL_0078: 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)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: 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)
			if (!Object.op_Implicit((Object)(object)_blockedText))
			{
				if (GUIManager.Instance == null)
				{
					Logger.LogDebug((object)"GUIManager instance is null");
					return;
				}
				if (!Object.op_Implicit((Object)(object)GUIManager.CustomGUIFront))
				{
					Logger.LogDebug((object)"GUIManager CustomGUI is null");
					return;
				}
				_blockedText = GUIManager.Instance.CreateText(OODConfig.VipMessage.Value, GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, -150f), GUIManager.Instance.AveriaSerifBold, 22, GUIManager.Instance.ValheimOrange, true, Color.black, 450f, 40f, false);
				_blockedText.SetActive(false);
			}
		}

		public static void DisplayBlockMenu()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if ((Object)(object)_coroutineManager == (Object)null)
			{
				GameObject val = new GameObject("CoroutineManager");
				_coroutineManager = val.AddComponent<CoroutineManager>();
				Object.DontDestroyOnLoad((Object)(object)val);
			}
			if (!Object.op_Implicit((Object)(object)_blockedText))
			{
				CreateBlockMenu();
			}
			if (_blockMenuCoroutine != null)
			{
				((MonoBehaviour)_coroutineManager).StopCoroutine(_blockMenuCoroutine);
			}
			_blockMenuCoroutine = ((MonoBehaviour)_coroutineManager).StartCoroutine(ShowBlockMenu());
		}

		private static IEnumerator ShowBlockMenu()
		{
			if (_blockedText.activeSelf)
			{
				_blockedText.SetActive(false);
				yield break;
			}
			_blockedText.SetActive(true);
			yield return (object)new WaitForSeconds(3f);
			_blockedText.SetActive(false);
		}
	}
}
namespace OdinOnDemand.Utils.UI
{
	public class AudioWaveformVisualizer : MonoBehaviour
	{
		public int barCount = 64;

		public int smoothing = 8;

		public RectTransform[] bars;

		public AudioSource audioSource;

		public Gradient colorGradient;

		public float spacing = 10f;

		public float minHeight = 0.001f;

		public float maxHeight = 10f;

		public bool enableGlowEffect = true;

		public bool enableOutlineEffect = true;

		private bool _initialUpdateDone = false;

		[SerializeField]
		private int midStartIndex = 10;

		[SerializeField]
		private int midEndIndex = 32;

		[SerializeField]
		private float midScalingFactor = OODConfig.VisualizerScaleFactorMid.Value;

		[SerializeField]
		private float highScalingFactor = OODConfig.VisualizerScaleFactorHigh.Value;

		[SerializeField]
		private float baseScalingFactor = OODConfig.VisualizerScaleFactorBase.Value;

		public void Setup(AudioSource audio)
		{
			audioSource = audio;
			CreateBars();
			CreateGradient();
			Update();
		}

		private void CreateGradient()
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_001a: 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_003c: 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_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			colorGradient = new Gradient();
			GradientColorKey[] array = (GradientColorKey[])(object)new GradientColorKey[3];
			array[0].color = Color.green;
			array[0].time = 0f;
			array[1].color = Color.yellow;
			array[1].time = 0.25f;
			array[2].color = new Color(255f, 165f, 0f);
			array[2].time = 1f;
			GradientAlphaKey[] array2 = (GradientAlphaKey[])(object)new GradientAlphaKey[2];
			array2[0].alpha = 1f;
			array2[0].time = 0f;
			array2[1].alpha = 1f;
			array2[1].time = 1f;
			colorGradient.SetKeys(array, array2);
		}

		private void CreateBars()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Expected O, but got Unknown
			//IL_01a8: 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)
			bars = (RectTransform[])(object)new RectTransform[barCount];
			float num = spacing * (float)(barCount - 1);
			Rect rect = ((Component)this).GetComponent<RectTransform>().rect;
			float num2 = (((Rect)(ref rect)).width - num) / (float)barCount;
			for (int i = 0; i < barCount; i++)
			{
				GameObject val = new GameObject("Bar " + i);
				val.transform.SetParent(((Component)this).transform, false);
				RectTransform val2 = val.AddComponent<RectTransform>();
				rect = ((Component)this).GetComponent<RectTransform>().rect;
				val2.sizeDelta = new Vector2(num2, ((Rect)(ref rect)).height);
				val2.anchorMin = new Vector2(0.5f, 0f);
				val2.anchorMax = new Vector2(0.5f, 1f);
				val2.pivot = new Vector2(0.5f, 0.5f);
				float num3 = (num2 + spacing) * (float)i;
				rect = ((Component)this).GetComponent<RectTransform>().rect;
				val2.anchoredPosition = new Vector2(num3 - ((Rect)(ref rect)).width / 2f + num2 / 2f, 0f);
				Image val3 = val.AddComponent<Image>();
				val3.sprite = Sprite.Create(Texture2D.whiteTexture, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f));
				if (enableGlowEffect)
				{
					((Graphic)val3).material = new Material(Shader.Find("UI/Default"));
					((Graphic)val3).material.EnableKeyword("_EMISSION");
					((Graphic)val3).material.SetColor("_EmissionColor", Color.white);
				}
				if (enableOutlineEffect)
				{
					Outline val4 = val.AddComponent<Outline>();
					((Shadow)val4).effectColor = Color.black;
				}
				bars[i] = val2;
			}
		}

		private void Update()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			if (_initialUpdateDone && !audioSource.isPlaying)
			{
				return;
			}
			float[] array = new float[128];
			audioSource.GetSpectrumData(array, 0, (FFTWindow)0);
			Transform parent = ((Component)this).transform.parent;
			Rect rect = ((Component)parent).GetComponent<RectTransform>().rect;
			float num = ((Rect)(ref rect)).height / parent.localScale.y;
			for (int i = 0; i < bars.Length; i++)
			{
				float num2 = 1f;
				if (i >= midStartIndex && i <= midEndIndex)
				{
					num2 = midScalingFactor;
				}
				else if (i > midEndIndex)
				{
					num2 = highScalingFactor;
				}
				if (i >= 0 && i <= 3)
				{
					num2 = 0.25f;
				}
				float num3 = array[i] * num2 * baseScalingFactor + minHeight;
				num3 = Mathf.Clamp(num3, minHeight, Mathf.Min(maxHeight, num));
				float num4 = Mathf.Lerp(((Transform)bars[i]).localScale.y, num3, Time.deltaTime * (float)smoothing);
				((Transform)bars[i]).localScale = new Vector3(1f, num4, 1f);
				((Graphic)((Component)bars[i]).GetComponent<Image>()).color = colorGradient.Evaluate(array[i] * num2 * 25f);
			}
			_initialUpdateDone = true;
		}
	}
	public class LoadingCircle : MonoBehaviour
	{
		private RectTransform rectComponent;

		private readonly float rotateSpeed = 200f;

		private void Start()
		{
			rectComponent = ((Component)this).GetComponent<RectTransform>();
		}

		private void Update()
		{
			if (((Behaviour)this).isActiveAndEnabled)
			{
				((Transform)rectComponent).Rotate(0f, 0f, rotateSpeed * Time.deltaTime);
			}
		}
	}
	public class ScrollingText : MonoBehaviour
	{
		public int maxLength = 20;

		public string message = "";

		public float speed = 0.2f;

		private int index;

		private Text textComponent;

		private void Start()
		{
			textComponent = ((Component)this).GetComponent<Text>();
			((MonoBehaviour)this).StartCoroutine(ScrollText());
		}

		private IEnumerator ScrollText()
		{
			int direction = 1;
			while (true)
			{
				if (message.Length <= maxLength)
				{
					textComponent.text = message;
					continue;
				}
				string scrollText = message.Substring(index, maxLength);
				textComponent.text = scrollText;
				yield return (object)new WaitForSeconds(speed);
				if (index + maxLength >= message.Length)
				{
					direction = -1;
				}
				else if (index <= 0)
				{
					direction = 1;
				}
				index += direction;
			}
		}
	}
	public class UIController
	{
		private BasePlayer _basePlayer;

		internal GameObject LoadingIndicatorObj;

		internal GameObject LockedIconObj;

		private Slider _masterVolumeSliderComponent;

		private GameObject _mutedVolumeObj;

		private Resources _oodResources;

		private GameObject _playlistIndexObj;

		private GameObject _playlistStringObj;

		internal Text PlaylistTrackText;

		private GameObject _previousPlaylistTrackObj;

		internal GameObject URLPanelObj;

		private GameObject _dynamicPanelObj;

		private GameObject _dynamicScrollViewObj;

		private GameObject _settingsPanelObj;

		private RectTransform _settingsPanelRT;

		private GameObject _skipPlaylistTrackObj;

		private GameObject _toggleLoopObj;

		internal GameObject ToggleShuffleObj;

		internal GameObject ToggleShuffleTextObj;

		internal GameObject UnlockedIconObj;

		private GameObject _unmutedVolumeObj;

		private GameObject _urlInputFieldObj;

		private Slider _volumeSlider;

		private Slider _volumeSliderDynamic;

		private Toggle _adminOnlyToggle;

		internal Image RadioPanelThumbnail;

		private ToggleGroup _entryToggleGroup;

		private Toggle _entryToggle;

		public readonly string[] LoadingMessages = new string[4] { "Processing", "Processing.", "Processing..", "Processing..." };

		private readonly RpcHandler _rpc = OdinOnDemandPlugin.RPCHandlers;

		private GameObject _toggleMuteButton;

		private GameObject _volumeSliderMainObj;

		private GameObject _volumeSliderDynamicObj;

		private GameObject _toogleLoopButton;

		private GameObject _toggleShuffle;

		private GameObject _toggleShuffleText;

		private Coroutine _debounceCoroutine;

		public const float DebounceTime = 0.3f;

		private const bool IsWaiting = false;

		private Text _loadingIndicatorText;

		private Transform _dynamicContentTransform;

		private GameObject _urlTabButtonObj;

		private GameObject _dynamicTabButtonObj;

		private InputField _urlInputField;

		private Text _speakerText;

		public UIController(BasePlayer basePlayer)
		{
			_basePlayer = basePlayer;
		}

		public void Initialize()
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			_oodResources = new Resources
			{
				knob = OdinOnDemandPlugin.UISprites["handle"],
				background = OdinOnDemandPlugin.UISprites["background"],
				standard = OdinOnDemandPlugin.UISprites["fill"],
				checkmark = OdinOnDemandPlugin.UISprites["checkmark"]
			};
		}

		public void DestroyUI()
		{
			if (Object.op_Implicit((Object)(object)URLPanelObj))
			{
				Object.Destroy((Object)(object)URLPanelObj);
			}
			if (Object.op_Implicit((Object)(object)_dynamicPanelObj))
			{
				Object.Destroy((Object)(object)_dynamicPanelObj);
			}
		}

		private void ToggleMute()
		{
			bool flag = _basePlayer.mAudio.volume > 0f;
			_basePlayer.mAudio.volume = (flag ? 0f : _basePlayer.PlayerSettings.MuteVol);
			if ((Object)(object)_mutedVolumeObj != (Object)null)
			{
				_mutedVolumeObj.SetActive(flag);
				_unmutedVolumeObj.SetActive(!flag);
			}
			_basePlayer.PlayerSettings.Volume = _basePlayer.mAudio.volume;
			_volumeSlider.value = _basePlayer.PlayerSettings.Volume;
			_volumeSliderDynamic.value = _basePlayer.PlayerSettings.Volume;
			if (flag)
			{
				_basePlayer.PlayerSettings.MuteVol = _basePlayer.PlayerSettings.Volume;
			}
		}

		internal void UpdatePlaylistInfo()
		{
			if (_basePlayer.PlayerSettings.IsPlayingPlaylist && Object.op_Implicit((Object)(object)URLPanelObj))
			{
				int num = _basePlayer.CurrentPlaylist.ElementAt(_basePlayer.PlaylistPosition).Title.Length;
				if (num > 14)
				{
					num = 14;
				}
				if (!_basePlayer.PlayerSettings.IsShuffling)
				{
					BasePlayer basePlayer = _basePlayer;
					string playlistString = (_basePlayer.PlaylistString = _basePlayer.CurrentPlaylist.ElementAt(_basePlayer.PlaylistPosition).Title);
					basePlayer.PlaylistString = playlistString;
					_basePlayer.PlaylistString = "Playing '" + _basePlayer.CurrentPlaylist.ElementAt(_basePlayer.PlaylistPosition).Title.Substring(0, num) + "...' ";
					_playlistIndexObj.GetComponent<Text>().text = _basePlayer.PlaylistPosition + 1 + "/" + _basePlayer.CurrentPlaylist.Count;
					PlaylistTrackText.text = _basePlayer.PlaylistString;
				}
				else
				{
					BasePlayer basePlayer2 = _basePlayer;
					string playlistString = (_basePlayer.PlaylistString = _basePlayer.CurrentPlaylist.ElementAt(_basePlayer.PlaylistPosition).Title);
					basePlayer2.PlaylistString = playlistString;
					_basePlayer.PlaylistString = "Playing '" + _basePlayer.CurrentPlaylist.ElementAt(_basePlayer.PlaylistPosition).Title.Substring(0, num) + "...' ";
					_playlistIndexObj.GetComponent<Text>().text = _basePlayer.PlaylistPosition + 1 + "/" + _basePlayer.CurrentPlaylist.Count + ", (shuffled)";
					PlaylistTrackText.text = _basePlayer.PlaylistString;
				}
			}
		}

		public void UpdatePlaylistUI()
		{
			if (Object.op_Implicit((Object)(object)_playlistStringObj))
			{
				_playlistStringObj.SetActive(_basePlayer.PlayerSettings.IsPlayingPlaylist);
			}
			if (Object.op_Implicit((Object)(object)_skipPlaylistTrackObj))
			{
				_skipPlaylistTrackObj.SetActive(_basePlayer.PlayerSettings.IsPlayingPlaylist);
			}
			if (Object.op_Implicit((Object)(object)_previousPlaylistTrackObj))
			{
				_previousPlaylistTrackObj.SetActive(_basePlayer.PlayerSettings.IsPlayingPlaylist);
			}
			if (Object.op_Implicit((Object)(object)ToggleShuffleObj))
			{
				ToggleShuffleObj.SetActive(_basePlayer.PlayerSettings.IsPlayingPlaylist);
			}
			if (Object.op_Implicit((Object)(object)ToggleShuffleTextObj))
			{
				ToggleShuffleTextObj.SetActive(_basePlayer.PlayerSettings.IsPlayingPlaylist);
			}
			if (Object.op_Implicit((Object)(object)_playlistIndexObj))
			{
				_playlistIndexObj.SetActive(_basePlayer.PlayerSettings.IsPlayingPlaylist);
			}
		}

		internal IEnumerator UnavailableIndicator(string message)
		{
			if (Object.op_Implicit((Object)(object)LoadingIndicatorObj))
			{
				LoadingIndicatorObj.GetComponent<Text>().text = message;
				LoadingIndicatorObj.SetActive(true);
				yield return (object)new WaitForSeconds(2f);
				LoadingIndicatorObj.SetActive(false);
			}
		}

		private void CreateMainGUI()
		{
			if (!Object.op_Implicit((Object)(object)URLPanelObj))
			{
				if (GUIManager.Instance == null)
				{
					Logger.LogDebug((object)"GUIManager instance is null");
					return;
				}
				if (!Object.op_Implicit((Object)(object)GUIManager.CustomGUIFront))
				{
					Logger.LogDebug((object)"GUIManager CustomGUI is null");
					return;
				}
				CreateURLPanel();
				CreateDynamicPanel();
				PopulateDynamicPanel();
			}
		}

		private void PopulateDynamicPanel()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			foreach (DynamicStation dynamicStation in StationManager.Instance.DynamicStations)
			{
				CreateDynamicAudioEntry(dynamicStation.Title, dynamicStation.Thumbnail, _dynamicContentTransform, new Vector2(0f, 0f), DynamicEntryValueChanged);
			}
		}

		private void DynamicEntryValueChanged(bool value)
		{
			Toggle val = _entryToggleGroup.ActiveToggles().FirstOrDefault();
			if ((Object)(object)val != (Object)null)
			{
				DynamicStation station = StationManager.Instance.GetStation(((Component)val).GetComponentInChildren<Text>().text);
				_basePlayer.SetDynamicStation(station);
			}
		}

		private void CreateDynamicPanel()
		{
			//IL_0032: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: 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_0104: 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_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_dynamicPanelObj))
			{
				_dynamicPanelObj = GUIManager.Instance.CreateWoodpanel(URLPanelObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 0f), 375f, 155f, true);
				_dynamicPanelObj.AddComponent<CustomDragHandler>().parentObj = URLPanelObj;
				_dynamicPanelObj.SetActive(false);
				_dynamicScrollViewObj = DefaultControls.CreateScrollView(_oodResources);
				ScrollRect component = _dynamicScrollViewObj.GetComponent<ScrollRect>();
				component.vertical = true;
				component.horizontal = false;
				_dynamicScrollViewObj.transform.SetParent(_dynamicPanelObj.transform, false);
				RectTransform component2 = _dynamicScrollViewObj.GetComponent<RectTransform>();
				component2.anchorMin = new Vector2(0f, 0f);
				component2.anchorMax = new Vector2(1f, 1f);
				component2.offsetMin = new Vector2(10f, 40f);
				component2.offsetMax = new Vector2(-10f, -16f);
				Image component3 = _dynamicScrollViewObj.GetComponent<Image>();
				((Graphic)component3).color = new Color(0.1f, 0.1f, 0.1f, 0.85f);
				((Component)_dynamicScrollViewObj.transform.Find("Scrollbar Vertical")).gameObject.SetActive(false);
				_dynamicContentTransform = _dynamicScrollViewObj.transform.Find("Viewport/Content");
				VerticalLayoutGroup val = ((Component)_dynamicContentTransform).gameObject.AddComponent<VerticalLayoutGroup>();
				((HorizontalOrVerticalLayoutGroup)val).childForceExpandWidth = true;
				((HorizontalOrVerticalLayoutGroup)val).childForceExpandHeight = true;
				((HorizontalOrVerticalLayoutGroup)val).childControlWidth = true;
				((HorizontalOrVerticalLayoutGroup)val).childControlHeight = true;
				((HorizontalOrVerticalLayoutGroup)val).childScaleHeight = true;
				((HorizontalOrVerticalLayoutGroup)val).childScaleWidth = true;
				((HorizontalOrVerticalLayoutGroup)val).spacing = 1f;
				_entryToggleGroup = ((Component)_dynamicContentTransform).gameObject.AddComponent<ToggleGroup>();
				_entryToggleGroup.allowSwitchOff = false;
				_entryToggleGroup.SetAllTogglesOff(true);
				CreateUISpriteButton("play", _dynamicPanelObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-150f, -57f), 34f, 34f, delegate
				{
					BasePlayer basePlayer = _basePlayer;
					Toggle? obj = _entryToggleGroup.ActiveToggles().FirstOrDefault();
					basePlayer.PlayStation((obj != null) ? ((Component)obj).GetComponentInChildren<Text>().text : null);
				});
				CreateUISpriteButton("stop", _dynamicPanelObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-112f, -57f), 34f, 34f, delegate
				{
					_basePlayer.Stop();
				});
				CreateMuteButton(new Vector2(150f, -57f), _dynamicPanelObj.transform);
				_volumeSliderDynamicObj = DefaultControls.CreateSlider(_oodResources);
				_volumeSliderDynamicObj.transform.SetParent(_dynamicPanelObj.transform);
				_volumeSliderDynamicObj.transform.localPosition = new Vector3(100f, -57f, 0f);
				_volumeSliderDynamicObj.transform.localScale = new Vector3(0.4f, 1.4f, 1.17f);
				Slider component4 = _volumeSliderDynamicObj.GetComponent<Slider>();
				component4.value = _basePlayer.PlayerSettings.Volume;
				_volumeSliderDynamic = component4;
				((UnityEvent<float>)(object)component4.onValueChanged).AddListener((UnityAction<float>)OnVolumeSliderChanged);
			}
		}

		private void CreateURLPanel()
		{
			//IL_001b: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_00dc: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: 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_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: 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_0447: 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_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_050e: Unknown result type (might be due to invalid IL or missing references)
			//IL_051d: Unknown result type (might be due to invalid IL or missing references)
			//IL_052c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0542: Unknown result type (might be due to invalid IL or missing references)
			//IL_0548: Unknown result type (might be due to invalid IL or missing references)
			//IL_05af: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b9: Expected O, but got Unknown
			//IL_05d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05df: Expected O, but got Unknown
			//IL_061a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0624: Expected O, but got Unknown
			//IL_063b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0645: Expected O, but got Unknown
			//IL_0665: Unknown result type (might be due to invalid IL or missing references)
			//IL_0674: 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_0699: Unknown result type (might be due to invalid IL or missing references)
			//IL_069f: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0704: 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_0720: Unknown result type (might be due to invalid IL or missing references)
			//IL_0775: Unknown result type (might be due to invalid IL or missing references)
			//IL_0784: Unknown result type (might be due to invalid IL or missing references)
			//IL_0793: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0835: Unknown result type (might be due to invalid IL or missing references)
			//IL_0844: Unknown result type (might be due to invalid IL or missing references)
			//IL_0853: Unknown result type (might be due to invalid IL or missing references)
			//IL_0895: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0901: Unknown result type (might be due to invalid IL or missing references)
			//IL_0910: Unknown result type (might be due to invalid IL or missing references)
			//IL_091f: Unknown result type (might be due to invalid IL or missing references)
			//IL_095d: Unknown result type (might be due to invalid IL or missing references)
			//IL_096c: Unknown result type (might be due to invalid IL or missing references)
			//IL_097b: Unknown result type (might be due to invalid IL or missing references)
			//IL_09bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_09cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_09db: Unknown result type (might be due to invalid IL or missing references)
			URLPanelObj = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, 0f), 375f, 155f, true);
			URLPanelObj.SetActive(false);
			GameObject val = GUIManager.Instance.CreateButton("X", URLPanelObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(168f, 90f), 32f, 32f);
			_urlInputFieldObj = GUIManager.Instance.CreateInputField(URLPanelObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-35f, 50f), (ContentType)0, "Enter video/song/playlist url...", 16, 250f, 30f);
			GameObject val2 = GUIManager.Instance.CreateButton("Set", URLPanelObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(130f, 50f), 64f, 32f);
			_urlInputField = _urlInputFieldObj.GetComponent<InputField>();
			CreateUISpriteButton("play", URLPanelObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-150f, 10f), 34f, 34f, delegate
			{
				_basePlayer.Play();
			});
			CreateUISpriteButton("pause", URLPanelObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-112f, 10f), 34f, 34f, delegate
			{
				_basePlayer.Pause();
			});
			CreateUISpriteButton("stop", URLPanelObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(-74f, 10f), 34f, 34f, delegate
			{
				_basePlayer.Stop();
			});
			CreateMuteButton(new Vector2(150f, 15f), URLPanelObj.transform);
			_volumeSliderMainObj = DefaultControls.CreateSlider(_oodResources);
			_volumeSliderMainObj.transform.SetParent(URLPanelObj.transform);
			_volumeSliderMainObj.transform.localPosition = new Vector3(100f, 15f, 0f);
			_volumeSliderMainObj.transform.localScale = new Vector3(0.4f, 1.4f, 1.17f);
			Slider component = _volumeSliderMainObj.GetComponent<Slider>();
			component.value = _basePlayer.PlayerSettings.Volume;
			_volumeSlider = component;
			((UnityEvent<float>)(object)component.onValueChanged).AddListener((UnityAction<float>)OnVolumeSliderChanged);
			GameObject val3 = GUIManager.Instance.CreateText("Processing", URLPanelObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(0f, -105f), GUIManager.Instance.AveriaSerifBold, 22, GUIManager.Instance.ValheimOrange, true, Color.black, 350f, 40f, false);
			val3.SetActive(false);
			_toogleLoopButton = GUIManager.Instance.CreateButton("N", URLPanelObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(154f, -14f), 25f, 25f);
			GUIManager.Instance.CreateText("Loop", URLPanelObj.transform, new Vector2(0.5f, 0.5f), new Vector2(0.5f, 0.5f), new Vector2(115f, -24f), GUIMa