Decompiled source of TootTallySongDownloader v1.0.3

plugins/TootTallySongDownloader.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BaboonAPI.Hooks.Initializer;
using BaboonAPI.Hooks.Tracks;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Microsoft.FSharp.Core;
using TMPro;
using TootTallyCore;
using TootTallyCore.APIServices;
using TootTallyCore.Graphics;
using TootTallyCore.Utils.Assets;
using TootTallyCore.Utils.Helpers;
using TootTallyCore.Utils.TootTallyModules;
using TootTallyCore.Utils.TootTallyNotifs;
using TootTallySettings;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("TootTallySongDownloader")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("In-game custom songs downloader")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("TootTallySongDownloader")]
[assembly: AssemblyTitle("TootTallySongDownloader")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TootTallySongDownloader
{
	[BepInPlugin("TootTallySongDownloader", "TootTallySongDownloader", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin, ITootTallyModule
	{
		public static Plugin Instance;

		private const string CONFIG_NAME = "ModuleTemplate.cfg";

		private Harmony _harmony;

		public static TootTallySettingPage settingPage;

		public ConfigEntry<bool> ModuleConfigEnabled { get; set; }

		public bool IsConfigInitialized { get; set; }

		public string Name
		{
			get
			{
				return "TootTallySongDownloader";
			}
			set
			{
				Name = value;
			}
		}

		public static void LogInfo(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)msg);
		}

		public static void LogWarning(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogWarning((object)msg);
		}

		public static void LogError(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogError((object)msg);
		}

		private void Awake()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			if (!((Object)(object)Instance != (Object)null))
			{
				Instance = this;
				_harmony = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				GameInitializationEvent.Register(((BaseUnityPlugin)this).Info, (Action)TryInitialize);
			}
		}

		private void TryInitialize()
		{
			ModuleConfigEnabled = ((BaseUnityPlugin)Plugin.Instance).Config.Bind<bool>("Modules", "SongDownloader", true, "In-game custom songs downloader.");
			TootTallyModuleManager.AddModule((ITootTallyModule)(object)this);
		}

		public void LoadModule()
		{
			AssetManager.LoadAssets(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Instance).Info.Location), "Assets"));
			settingPage = TootTallySettingsManager.AddNewPage((TootTallySettingPage)(object)new SongDownloadPage());
			Plugin.TryAddThunderstoreIconToPageButton(((BaseUnityPlugin)Instance).Info.Location, Name, settingPage);
			LogInfo("Module loaded!");
		}

		public void UnloadModule()
		{
			_harmony.UnpatchSelf();
			settingPage.Remove();
			LogInfo("Module unloaded!");
		}
	}
	internal class SongDownloadObject : BaseTootTallySettingObject
	{
		private const string _DOWNLOAD_MIRROR_LINK = "https://toottally.sgp1.digitaloceanspaces.com/toottally/chartmirrors/";

		private const string _PIXELDRAIN_DOWNLOAD_LINK = "https://pixeldrain.com/api/file/";

		private const string _DISCORD_DOWNLOAD_HEADER = "https://cdn.discordapp.com/";

		private const string _GOOGLEDRIVE_LINK_HEADER = "https://drive.google.com/file/d/";

		private const string _GOOGLEDRIVE_DOWNLOAD_HEADER = "https://drive.google.com/uc?export=download&id=";

		private GameObject _songRowContainer;

		private GameObject _songRow;

		private SongDataFromDB _song;

		private GameObject _downloadButton;

		private ProgressBar _progressBar;

		private TMP_Text _fileSizeText;

		private TMP_Text _durationText;

		public bool isDownloadAvailable;

		public bool isOwned;

		private Coroutine _fileSizeCoroutine;

		public SongDownloadObject(Transform canvasTransform, SongDataFromDB song, SongDownloadPage page)
			: base("Song" + song.track_ref, (TootTallySettingPage)(object)page)
		{
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: 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_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			SongDownloadObject songDownloadObject = this;
			_song = song;
			_songRow = Object.Instantiate<GameObject>(page.songRowPrefab, canvasTransform);
			((Object)_songRow).name = "Song" + song.track_ref;
			_songRowContainer = ((Component)_songRow.transform.Find("LatencyFG/MainPage")).gameObject;
			TimeSpan timeSpan = TimeSpan.FromSeconds(song.song_length);
			string text = string.Format("{0}{1}:{2:00}", (timeSpan.Hours != 0) ? (timeSpan.Hours + ":") : "", (timeSpan.Minutes != 0) ? ((object)timeSpan.Minutes) : "0", (timeSpan.Seconds != 0) ? ((object)timeSpan.Seconds) : "00");
			TMP_Text val = GameObjectFactory.CreateSingleText(_songRowContainer.transform, "SongName", song.name, (TextFont)0);
			TMP_Text val2 = GameObjectFactory.CreateSingleText(_songRowContainer.transform, "Charter", (song.charter != null) ? ("Mapped by " + song.charter) : "Unknown", (TextFont)0);
			_durationText = GameObjectFactory.CreateSingleText(_songRowContainer.transform, "Duration", text, (TextFont)0);
			_fileSizeText = GameObjectFactory.CreateSingleText(_songRowContainer.transform, "FileSize", "", (TextFont)0);
			((Component)_fileSizeText).GetComponent<RectTransform>().sizeDelta = new Vector2(100f, 128f);
			((Component)_fileSizeText).gameObject.SetActive(false);
			RectTransform component = ((Component)val).GetComponent<RectTransform>();
			RectTransform component2 = ((Component)val2).GetComponent<RectTransform>();
			Vector2 sizeDelta = default(Vector2);
			((Vector2)(ref sizeDelta))..ctor(250f, 128f);
			component2.sizeDelta = sizeDelta;
			component.sizeDelta = sizeDelta;
			((Component)_durationText).GetComponent<RectTransform>().sizeDelta = new Vector2(230f, 128f);
			TMP_Text durationText = _durationText;
			TextOverflowModes val3 = (TextOverflowModes)1;
			durationText.overflowMode = (TextOverflowModes)1;
			TextOverflowModes overflowMode = (val2.overflowMode = val3);
			val.overflowMode = overflowMode;
			if (FSharpOption<TromboneTrack>[TrackLookup.tryLookup(song.track_ref)] && !(base._page as SongDownloadPage).IsAlreadyDownloaded(song.track_ref))
			{
				string link = FileHelper.GetDownloadLinkFromSongData(song);
				if (link != null)
				{
					_fileSizeCoroutine = ((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.GetFileSize(link, (Action<FileData>)delegate(FileData fileData)
					{
						//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
						//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
						//IL_0138: Unknown result type (might be due to invalid IL or missing references)
						//IL_0147: Unknown result type (might be due to invalid IL or missing references)
						if (fileData != null)
						{
							songDownloadObject.DisplaySizeFileText(fileData.size);
							if (!fileData.extension.Contains("zip"))
							{
								songDownloadObject.DisplayNotAvailableText("File is not zip: " + fileData.extension + ".", 4);
							}
							else
							{
								songDownloadObject._fileSizeCoroutine = null;
								songDownloadObject.isDownloadAvailable = true;
								songDownloadObject._downloadButton = ((Component)GameObjectFactory.CreateCustomButton(songDownloadObject._songRowContainer.transform, Vector2.zero, new Vector2(64f, 64f), AssetManager.GetSprite("Download64.png"), "DownloadButton", (Action)songDownloadObject.DownloadChart)).gameObject;
								songDownloadObject._downloadButton.transform.SetSiblingIndex(4);
								songDownloadObject._progressBar = GameObjectFactory.CreateProgressBar(songDownloadObject._songRow.transform.Find("LatencyFG"), Vector2.zero, new Vector2(900f, 20f), false, "ProgressBar");
								(((BaseTootTallySettingObject)songDownloadObject)._page as SongDownloadPage).UpdateDownloadAllButton();
							}
						}
						else
						{
							songDownloadObject.DisplayNotAvailableText("Couldn't access file at " + link, 3);
						}
					}));
				}
				else
				{
					DisplayNotAvailableText("No download link found.");
				}
			}
			else
			{
				DisplayOwnedText();
			}
			GameObjectFactory.CreateCustomButton(_songRowContainer.transform, Vector2.zero, new Vector2(64f, 64f), AssetManager.GetSprite("global64.png"), "OpenWebButton", (Action)delegate
			{
				Application.OpenURL($"https://toottally.com/song/{song.id}/");
			});
			_songRow.SetActive(true);
		}

		public void DisplaySizeFileText(long size)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			string text = FileHelper.SizeSuffix(size, 2);
			_fileSizeText.text = text;
			((Component)_fileSizeText).gameObject.SetActive(true);
			((Component)_durationText).GetComponent<RectTransform>().sizeDelta = new Vector2(100f, 128f);
		}

		public void DisplayNotAvailableText(string error, int siblingIndex = -1)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			Plugin.LogWarning(_song.track_ref + " cannot be downloaded: " + error);
			TMP_Text val = GameObjectFactory.CreateSingleText(_songRowContainer.transform, "N/A", "N/A", (TextFont)0);
			((Component)val).GetComponent<RectTransform>().sizeDelta = new Vector2(64f, 128f);
			val.overflowMode = (TextOverflowModes)0;
			val.enableWordWrapping = false;
			if (siblingIndex != -1)
			{
				val.transform.SetSiblingIndex(siblingIndex);
			}
		}

		public void DisplayOwnedText()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			isOwned = true;
			TMP_Text val = GameObjectFactory.CreateSingleText(_songRowContainer.transform, "Owned", "Owned", (TextFont)0);
			((Component)val).GetComponent<RectTransform>().sizeDelta = new Vector2(64f, 128f);
			val.overflowMode = (TextOverflowModes)0;
			val.enableWordWrapping = false;
		}

		public void SetActive(bool active)
		{
			_songRow.SetActive(active);
		}

		public override void Dispose()
		{
			Object.DestroyImmediate((Object)(object)_songRow);
			if (_fileSizeCoroutine != null)
			{
				((MonoBehaviour)Plugin.Instance).StopCoroutine(_fileSizeCoroutine);
			}
		}

		public void DownloadChart()
		{
			isDownloadAvailable = false;
			_downloadButton.SetActive(false);
			((Component)_fileSizeText).gameObject.SetActive(false);
			string text = _song.mirror ?? _song.download;
			((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.DownloadZipFromServer(text, _progressBar, (Action<byte[]>)delegate(byte[] data)
			{
				//IL_00c5: 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 (data != null)
				{
					string text2 = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Plugin.Instance).Info.Location), "Downloads/");
					string text3 = $"{_song.id}.zip";
					if (!Directory.Exists(text2))
					{
						Directory.CreateDirectory(text2);
					}
					FileHelper.WriteBytesToFile(text2, text3, data);
					string text4 = Path.Combine(text2, text3);
					string text5 = Path.Combine(Paths.BepInExRootPath, "CustomSongs/");
					FileHelper.ExtractZipToDirectory(text4, text5);
					FileHelper.DeleteFile(text2, text3);
					TMP_Text val = GameObjectFactory.CreateSingleText(_songRowContainer.transform, "Owned", "Owned", (TextFont)0);
					isOwned = true;
					((Component)val).GetComponent<RectTransform>().sizeDelta = new Vector2(64f, 128f);
					val.overflowMode = (TextOverflowModes)0;
					val.enableWordWrapping = false;
					val.transform.SetSiblingIndex(3);
					((Component)_durationText).GetComponent<RectTransform>().sizeDelta = new Vector2(230f, 128f);
					SongDownloadPage songDownloadPage = base._page as SongDownloadPage;
					songDownloadPage.AddTrackRefToDownloadedSong(_song.track_ref);
					SetActive(!songDownloadPage.ShowNotOwnedOnly);
				}
				else
				{
					TootTallyNotifManager.DisplayNotif("Download failed.", 6f);
					_downloadButton.SetActive(true);
				}
			}));
		}
	}
	internal class SongDownloadPage : TootTallySettingPage
	{
		private const string DEFAULT_INPUT_TEXT = "SearchHere";

		private TMP_InputField _inputField;

		private GameObject _searchButton;

		private GameObject _nextButton;

		private GameObject _prevButton;

		private GameObject _downloadAllButton;

		private Toggle _toggleRated;

		private Toggle _toggleUnrated;

		private Toggle _toggleNotOwned;

		private LoadingIcon _loadingIcon;

		internal GameObject songRowPrefab;

		private List<string> _trackRefList;

		private List<string> _newDownloadedTrackRefs;

		private List<SongDownloadObject> _downloadObjectList;

		public bool ShowNotOwnedOnly => _toggleNotOwned.isOn;

		private static ColorBlock GetButtonColors
		{
			get
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_006d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				ColorBlock result = default(ColorBlock);
				((ColorBlock)(ref result)).normalColor = new Color(0.2f, 0.2f, 1f);
				((ColorBlock)(ref result)).highlightedColor = new Color(0.15f, 0.15f, 0.65f);
				((ColorBlock)(ref result)).pressedColor = new Color(0.5f, 0.5f, 0.75f);
				((ColorBlock)(ref result)).selectedColor = new Color(0.2f, 0.2f, 1f);
				((ColorBlock)(ref result)).fadeDuration = 0.08f;
				((ColorBlock)(ref result)).colorMultiplier = 1f;
				return result;
			}
		}

		public SongDownloadPage()
			: base("MoreSongs", "More Songs", 20f, new Color(0f, 0f, 0f, 0.1f), GetButtonColors)
		{
		}//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)


		public override void Initialize()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: 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_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Expected O, but got Unknown
			((TootTallySettingPage)this).Initialize();
			_trackRefList = new List<string>();
			_newDownloadedTrackRefs = new List<string>();
			_downloadObjectList = new List<SongDownloadObject>();
			_inputField = TootTallySettingObjectFactory.CreateInputField(base._fullPanel.transform, base.name + "InputField", TootTallySettingPage.DEFAULT_OBJECT_SIZE, TootTallySettingPage.DEFAULT_FONTSIZE, "SearchHere", false);
			((UnityEvent<string>)(object)_inputField.onSubmit).AddListener((UnityAction<string>)delegate
			{
				Search(_inputField.text);
			});
			RectTransform component = ((Component)_inputField).GetComponent<RectTransform>();
			RectTransform component2 = ((Component)_inputField).GetComponent<RectTransform>();
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.72f, 0.7f);
			component2.anchorMax = val;
			component.anchorMin = val;
			_loadingIcon = GameObjectFactory.CreateLoadingIcon(base._fullPanel.transform, new Vector2(-300f, -75f), new Vector2(128f, 128f), AssetManager.GetSprite("icon.png"), false, "SongSearchLoadingSwirly");
			_searchButton = ((Component)GameObjectFactory.CreateCustomButton(base._fullPanel.transform, new Vector2(-375f, -175f), TootTallySettingPage.DEFAULT_OBJECT_SIZE, "Search", base.name + "SearchButton", (Action)delegate
			{
				Search(_inputField.text);
			})).gameObject;
			_toggleRated = TootTallySettingObjectFactory.CreateToggle(base._fullPanel.transform, base.name + "ToggleRated", new Vector2(200f, 60f), "Rated", (ConfigEntry<bool>)null);
			RectTransform component3 = ((Component)_toggleRated).GetComponent<RectTransform>();
			RectTransform component4 = ((Component)_toggleRated).GetComponent<RectTransform>();
			((Vector2)(ref val))..ctor(0.63f, 0.58f);
			component4.anchorMax = val;
			component3.anchorMin = val;
			((UnityEvent<bool>)(object)_toggleRated.onValueChanged).AddListener((UnityAction<bool>)delegate(bool value)
			{
				if (value)
				{
					_toggleUnrated.SetIsOnWithoutNotify(!value);
				}
			});
			_toggleUnrated = TootTallySettingObjectFactory.CreateToggle(base._fullPanel.transform, base.name + "ToggleUnrated", new Vector2(200f, 60f), "Unrated", (ConfigEntry<bool>)null);
			RectTransform component5 = ((Component)_toggleUnrated).GetComponent<RectTransform>();
			RectTransform component6 = ((Component)_toggleUnrated).GetComponent<RectTransform>();
			((Vector2)(ref val))..ctor(0.63f, 0.5f);
			component6.anchorMax = val;
			component5.anchorMin = val;
			((UnityEvent<bool>)(object)_toggleUnrated.onValueChanged).AddListener((UnityAction<bool>)delegate(bool value)
			{
				if (value)
				{
					_toggleRated.SetIsOnWithoutNotify(!value);
				}
			});
			_toggleNotOwned = TootTallySettingObjectFactory.CreateToggle(base._fullPanel.transform, base.name + "ToggleNotOwned", new Vector2(200f, 60f), "Not Owned", (ConfigEntry<bool>)null);
			RectTransform component7 = ((Component)_toggleNotOwned).GetComponent<RectTransform>();
			RectTransform component8 = ((Component)_toggleNotOwned).GetComponent<RectTransform>();
			((Vector2)(ref val))..ctor(0.63f, 0.42f);
			component8.anchorMax = val;
			component7.anchorMin = val;
			((UnityEvent<bool>)(object)_toggleNotOwned.onValueChanged).AddListener((UnityAction<bool>)OnNotOwnedToggle);
			_downloadAllButton = ((Component)GameObjectFactory.CreateCustomButton(base._fullPanel.transform, new Vector2(-1330f, -87f), new Vector2(200f, 60f), "Download All", "DownloadAllButton", (Action)DownloadAll)).gameObject;
			_downloadAllButton.SetActive(false);
			SetSongRowPrefab();
			((UnityEvent)base._backButton.button.onClick).AddListener((UnityAction)delegate
			{
				if (_newDownloadedTrackRefs.Count > 0)
				{
					TootTallyNotifManager.DisplayNotif("New tracks detected, Reloading songs...\nLagging is normal.", 6f);
					_newDownloadedTrackRefs.Clear();
					((MonoBehaviour)Plugin.Instance).Invoke("ReloadTracks", 0.35f);
				}
			});
			base._scrollableSliderHandler.accelerationMult = 0.09f;
		}

		public override void OnShow()
		{
			_loadingIcon.StartRecursiveAnimation();
		}

		public override void OnHide()
		{
			_loadingIcon.StopRecursiveAnimation(true);
		}

		private void Search(string input, bool searchWithFilter = true)
		{
			if (input == "SearchHere")
			{
				input = "";
			}
			_downloadObjectList.Clear();
			_downloadAllButton.SetActive(false);
			((TootTallySettingPage)this).RemoveAllObjects();
			_searchButton.SetActive(false);
			_loadingIcon.Show();
			if ((Object)(object)_nextButton != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)_nextButton);
				_nextButton = null;
			}
			if ((Object)(object)_prevButton != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)_prevButton);
				_prevButton = null;
			}
			_trackRefList.Clear();
			if (searchWithFilter)
			{
				((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.SearchSongWithFilters(input, _toggleRated.isOn, _toggleUnrated.isOn, (Action<SongInfoFromDB>)OnSearchInfoRecieved));
			}
			else
			{
				((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.SearchSongByURL(input, (Action<SongInfoFromDB>)OnSearchInfoRecieved));
			}
		}

		private void OnSearchInfoRecieved(SongInfoFromDB searchInfo)
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: 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_016b: Unknown result type (might be due to invalid IL or missing references)
			_searchButton.SetActive(true);
			_loadingIcon.Hide();
			base._verticalSlider.value = 0f;
			searchInfo.results.OrderByDescending((SongDataFromDB x) => x.id).ToList()?.ForEach(AddSongToPage);
			((Component)base._verticalSlider).gameObject.SetActive(searchInfo.results.Length > 5);
			((Behaviour)base._scrollableSliderHandler).enabled = searchInfo.results.Length > 5;
			if (searchInfo.next != null)
			{
				_nextButton = ((Component)GameObjectFactory.CreateCustomButton(base._fullPanel.transform, new Vector2(-350f, -175f), new Vector2(50f, 50f), ">>", base.name + "NextButton", (Action)delegate
				{
					Search(searchInfo.next, searchWithFilter: false);
				})).gameObject;
			}
			if (searchInfo.previous != null)
			{
				_prevButton = ((Component)GameObjectFactory.CreateCustomButton(base._fullPanel.transform, new Vector2(-700f, -175f), new Vector2(50f, 50f), "<<", base.name + "PrevButton", (Action)delegate
				{
					Search(searchInfo.previous, searchWithFilter: false);
				})).gameObject;
			}
		}

		public void UpdateDownloadAllButton()
		{
			if (!_downloadAllButton.activeSelf)
			{
				_downloadAllButton.SetActive(_downloadObjectList.Any((SongDownloadObject o) => o.isDownloadAvailable));
			}
		}

		private void DownloadAll()
		{
			_downloadAllButton.SetActive(false);
			CollectionExtensions.Do<SongDownloadObject>(_downloadObjectList.Where((SongDownloadObject o) => o.isDownloadAvailable), (Action<SongDownloadObject>)delegate(SongDownloadObject o)
			{
				o.DownloadChart();
			});
		}

		private void AddSongToPage(SongDataFromDB song)
		{
			if (!_trackRefList.Contains(song.track_ref))
			{
				_trackRefList.Add(song.track_ref);
				SongDownloadObject songDownloadObject = new SongDownloadObject(base.gridPanel.transform, song, this);
				songDownloadObject.SetActive(!_toggleNotOwned.isOn || !songDownloadObject.isOwned);
				_downloadObjectList.Add(songDownloadObject);
				((TootTallySettingPage)this).AddSettingObjectToList((BaseTootTallySettingObject)(object)songDownloadObject);
			}
		}

		private void OnNotOwnedToggle(bool value)
		{
			_downloadObjectList.ForEach(delegate(SongDownloadObject x)
			{
				x.SetActive(!value || !x.isOwned);
			});
		}

		public void SetSongRowPrefab()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			GameObject gameObject = ((Component)GameObjectFactory.CreateOverlayPanel(base._fullPanel.transform, Vector2.zero, new Vector2(1030f, 140f), 5f, "TwitchRequestRowTemp").transform.Find("FSLatencyPanel")).gameObject;
			songRowPrefab = Object.Instantiate<GameObject>(gameObject);
			Object.DestroyImmediate((Object)(object)gameObject.gameObject);
			((Object)songRowPrefab).name = "RequestRowPrefab";
			songRowPrefab.transform.localScale = Vector3.one;
			((MaskableGraphic)songRowPrefab.GetComponent<Image>()).maskable = true;
			songRowPrefab.GetComponent<RectTransform>().sizeDelta = new Vector2(1050f, 160f);
			GameObject gameObject2 = ((Component)songRowPrefab.transform.Find("LatencyFG/MainPage")).gameObject;
			gameObject2.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
			gameObject2.GetComponent<RectTransform>().sizeDelta = new Vector2(1050f, 160f);
			Object.DestroyImmediate((Object)(object)((Component)gameObject2.transform.parent.Find("subtitle")).gameObject);
			Object.DestroyImmediate((Object)(object)((Component)gameObject2.transform.parent.Find("title")).gameObject);
			Object.DestroyImmediate((Object)(object)gameObject2.GetComponent<VerticalLayoutGroup>());
			HorizontalLayoutGroup val = gameObject2.AddComponent<HorizontalLayoutGroup>();
			((LayoutGroup)val).padding = new RectOffset(20, 20, 20, 20);
			((HorizontalOrVerticalLayoutGroup)val).spacing = 30f;
			((LayoutGroup)val).childAlignment = (TextAnchor)3;
			bool childControlHeight = (((HorizontalOrVerticalLayoutGroup)val).childControlWidth = false);
			((HorizontalOrVerticalLayoutGroup)val).childControlHeight = childControlHeight;
			childControlHeight = (((HorizontalOrVerticalLayoutGroup)val).childForceExpandWidth = false);
			((HorizontalOrVerticalLayoutGroup)val).childForceExpandHeight = childControlHeight;
			((MaskableGraphic)((Component)songRowPrefab.transform.Find("LatencyFG")).GetComponent<Image>()).maskable = true;
			((Graphic)((Component)songRowPrefab.transform.Find("LatencyFG")).GetComponent<Image>()).color = new Color(0.1f, 0.1f, 0.1f);
			((MaskableGraphic)((Component)songRowPrefab.transform.Find("LatencyBG")).GetComponent<Image>()).maskable = true;
			Object.DontDestroyOnLoad((Object)(object)songRowPrefab);
			songRowPrefab.SetActive(false);
		}

		public void AddTrackRefToDownloadedSong(string trackref)
		{
			_newDownloadedTrackRefs.Add(trackref);
		}

		public bool IsAlreadyDownloaded(string trackref)
		{
			return _newDownloadedTrackRefs.Contains(trackref);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TootTallySongDownloader";

		public const string PLUGIN_NAME = "TootTallySongDownloader";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}