Decompiled source of TootTallyAccounts v1.0.2

plugins/TootTallyAccounts.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BaboonAPI.Hooks.Initializer;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using TootTallyCore;
using TootTallyCore.APIServices;
using TootTallyCore.Graphics;
using TootTallyCore.Graphics.Animations;
using TootTallyCore.Utils.Assets;
using TootTallyCore.Utils.TootTallyModules;
using TootTallyCore.Utils.TootTallyNotifs;
using TootTallySettings;
using UnityEngine;
using UnityEngine.Events;

[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("TootTallyAccounts")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("TootTally Account Management module")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("TootTallyAccounts")]
[assembly: AssemblyTitle("TootTallyAccounts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 TootTallyAccounts
{
	[BepInPlugin("TootTallyAccounts", "TootTallyAccounts", "1.0.2")]
	[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 = "TootTally.cfg";

		public const string DEFAULT_APIKEY = "SignUpOnTootTally.com";

		private Harmony _harmony;

		public static TootTallySettingPage settingPage;

		public static string GetAPIKey => Instance.APIKey.Value;

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

		public bool IsConfigInitialized { get; set; }

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

		public ConfigEntry<string> APIKey { get; set; }

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

		public static void LogInfo(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((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", "TootTally Accounts", true, "Account management for TootTallyCore");
			TootTallyModuleManager.AddModule((ITootTallyModule)(object)this);
		}

		public void LoadModule()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			string text = Path.Combine(Paths.BepInExRootPath, "config/");
			ConfigFile val = new ConfigFile(text + "TootTally.cfg", true);
			APIKey = ((BaseUnityPlugin)this).Config.Bind<string>("API Setup", "API Key", "SignUpOnTootTally.com", "API Key for Score Submissions.");
			ShowLoginPanel = ((BaseUnityPlugin)this).Config.Bind<bool>("API Setup", "Show Login Panel", true, "Show login panel when not logged in.");
			Plugin.MainTootTallySettingPage.AddButton("OpenLoginPage", new Vector2(400f, 60f), "Open Login Page", (Action)TootTallyUser.OpenLoginPanel);
			Plugin.MainTootTallySettingPage.AddToggle("Show Login Panel", ShowLoginPanel, (UnityAction<bool>)null);
			string text2 = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Instance).Info.Location), "Assets");
			AssetManager.LoadAssets(text2);
			AssetBundleManager.LoadAssets(Path.Combine(text2, "loginassets"));
			_harmony.PatchAll(typeof(TootTallyUser));
			_harmony.PatchAll(typeof(UserStatusUpdater));
			((Component)this).gameObject.AddComponent<UserStatusManager>();
			LogInfo("Module loaded!");
		}

		public void UnloadModule()
		{
			_harmony.UnpatchSelf();
			LogInfo("Module unloaded!");
		}
	}
	public class TootTallyLoginPanel
	{
		private enum LogoNames
		{
			Question,
			TootTally,
			Patreon,
			Twitter,
			Discord
		}

		private Canvas _canvas;

		private GameObject _gameObject;

		private GameObject _mainPanelBG;

		private GameObject _mainPanelFG;

		private GameObject _menuMain;

		private GameObject _loginMain;

		private GameObject _signUpMain;

		private GameObject _helpMain;

		private GameObject _loadingMain;

		private GameObject _keybindsMain;

		private GameObject _topPanel;

		private GameObject _bottomPanel;

		private GameObject _topLeftContainer;

		private GameObject _topRightContainer;

		private GameObject _bottomLeftContainer;

		private GameObject _bottomRightContainer;

		private GameObject _previousPage;

		private GameObject _activePage;

		private TMP_Text _titleText;

		private LoadingIcon _loadingIcon;

		private TMP_InputField _loginUsername;

		private TMP_InputField _loginPassword;

		private TMP_InputField _signUpUsername;

		private TMP_InputField _signUpPassword;

		private TMP_InputField _signUpConfirm;

		private TMP_Text _fatHelpText;

		private TMP_Text _leftKeybindsText;

		private TMP_Text _rightKeybindsText;

		public TootTallyLoginPanel()
		{
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: 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_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_0521: Unknown result type (might be due to invalid IL or missing references)
			//IL_0526: Unknown result type (might be due to invalid IL or missing references)
			//IL_053d: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0579: Unknown result type (might be due to invalid IL or missing references)
			//IL_0588: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05da: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0613: Unknown result type (might be due to invalid IL or missing references)
			//IL_061e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0623: Unknown result type (might be due to invalid IL or missing references)
			//IL_063b: Unknown result type (might be due to invalid IL or missing references)
			//IL_064a: Unknown result type (might be due to invalid IL or missing references)
			//IL_067e: Unknown result type (might be due to invalid IL or missing references)
			//IL_068d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0692: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0732: Unknown result type (might be due to invalid IL or missing references)
			//IL_0737: Unknown result type (might be due to invalid IL or missing references)
			//IL_0779: Unknown result type (might be due to invalid IL or missing references)
			//IL_078f: Unknown result type (might be due to invalid IL or missing references)
			//IL_079e: Unknown result type (might be due to invalid IL or missing references)
			//IL_07cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0839: Unknown result type (might be due to invalid IL or missing references)
			//IL_0859: Unknown result type (might be due to invalid IL or missing references)
			//IL_085e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0880: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e9: Unknown result type (might be due to invalid IL or missing references)
			_gameObject = Object.Instantiate<GameObject>(AssetBundleManager.GetPrefab("toottallylogincanvas"));
			Object.DontDestroyOnLoad((Object)(object)_gameObject);
			_canvas = _gameObject.GetComponent<Canvas>();
			_mainPanelBG = ((Component)_gameObject.transform.GetChild(0)).gameObject;
			_mainPanelFG = ((Component)_mainPanelBG.transform.GetChild(0)).gameObject;
			_topPanel = ((Component)_mainPanelFG.transform.GetChild(0)).gameObject;
			_topLeftContainer = ((Component)_topPanel.gameObject.transform.GetChild(0)).gameObject;
			_topRightContainer = ((Component)_topPanel.gameObject.transform.GetChild(1)).gameObject;
			_menuMain = ((Component)_mainPanelFG.transform.GetChild(1)).gameObject;
			_loginMain = ((Component)_mainPanelFG.transform.GetChild(2)).gameObject;
			_signUpMain = ((Component)_mainPanelFG.transform.GetChild(3)).gameObject;
			_helpMain = ((Component)_mainPanelFG.transform.GetChild(4)).gameObject;
			_loadingMain = ((Component)_mainPanelFG.transform.GetChild(5)).gameObject;
			_keybindsMain = ((Component)_mainPanelFG.transform.GetChild(6)).gameObject;
			_bottomPanel = ((Component)_mainPanelFG.transform.GetChild(7)).gameObject;
			_bottomLeftContainer = ((Component)_bottomPanel.gameObject.transform.GetChild(0)).gameObject;
			_bottomRightContainer = ((Component)_bottomPanel.gameObject.transform.GetChild(1)).gameObject;
			_activePage = _menuMain;
			_titleText = GameObjectFactory.CreateSingleText(_topLeftContainer.transform, "WelcomeText", "Welcome to toottally", Color.white, (TextFont)0);
			_titleText.fontSize = 66f;
			_titleText.fontStyle = (FontStyles)17;
			GameObjectFactory.CreateDefaultButton(_menuMain.transform, Vector2.zero, new Vector2(325f, 85f), "LOGIN", 48, "LoginButton", (Action)OnLoginButtonClick);
			GameObjectFactory.CreateDefaultButton(_menuMain.transform, Vector2.zero, new Vector2(325f, 85f), "SIGN-UP", 48, "SignUpButton", (Action)OnSignUpButtonClick);
			GameObjectFactory.CreateDefaultButton(_menuMain.transform, Vector2.zero, new Vector2(250f, 40f), "Don't Show Again", 20, "DontShowAgain", (Action)OnDontShowAgainClick);
			GameObjectFactory.CreateCustomButton(_topRightContainer.transform, Vector2.zero, Vector2.one * 72f, AssetManager.GetSprite("Close64.png"), false, "ReturnButton", (Action)ReturnToHomePage);
			GameObjectFactory.CreateClickableImageHolder(_bottomLeftContainer.transform, Vector2.zero, Vector2.one * 72f, AssetManager.GetSprite("question128.png"), "QuestionButton", (Action)delegate
			{
				OnLogoButtonClick(LogoNames.Question);
			});
			GameObjectFactory.CreateClickableImageHolder(_bottomRightContainer.transform, Vector2.zero, Vector2.one * 92f, AssetManager.GetSprite("toottally128.png"), "TootTallyIcon", (Action)delegate
			{
				OnLogoButtonClick(LogoNames.TootTally);
			});
			GameObjectFactory.CreateClickableImageHolder(_bottomRightContainer.transform, Vector2.zero, Vector2.one * 72f, AssetManager.GetSprite("patreon128.png"), "PatreonButton", (Action)delegate
			{
				OnLogoButtonClick(LogoNames.Patreon);
			});
			GameObjectFactory.CreateClickableImageHolder(_bottomRightContainer.transform, Vector2.zero, Vector2.one * 86f, AssetManager.GetSprite("twitter128.png"), "TwitterButton", (Action)delegate
			{
				OnLogoButtonClick(LogoNames.Twitter);
			});
			GameObjectFactory.CreateClickableImageHolder(_bottomRightContainer.transform, Vector2.zero, Vector2.one * 96f, AssetManager.GetSprite("discord128.png"), "DiscordButton", (Action)delegate
			{
				OnLogoButtonClick(LogoNames.Discord);
			});
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.7f, 0f);
			_loginUsername = GameObjectFactory.CreateInputField(_loginMain.transform, Vector2.zero, new Vector2(350f, 25f), "LoginNameInput", false);
			GameObjectFactory.CreateSingleText(((Component)_loginUsername).transform, "UsernameText", "Username:", val, new Vector2(350f, 25f), Color.white, (TextFont)0);
			_loginPassword = GameObjectFactory.CreateInputField(_loginMain.transform, Vector2.zero, new Vector2(350f, 25f), "PasswordNameInput", true);
			GameObjectFactory.CreateSingleText(((Component)_loginPassword).transform, "PasswordText", "Password:", val, new Vector2(350f, 25f), Color.white, (TextFont)0);
			GameObjectFactory.CreateCustomButton(_loginMain.transform, Vector2.zero, new Vector2(225f, 45f), "Login", "SubmitLoginButton", (Action)OnSubmitLogin);
			_signUpUsername = GameObjectFactory.CreateInputField(_signUpMain.transform, Vector2.zero, new Vector2(350f, 25f), "LoginNameInput", false);
			GameObjectFactory.CreateSingleText(((Component)_signUpUsername).transform, "UsernameText", "Username:", val, new Vector2(350f, 25f), Color.white, (TextFont)0);
			_signUpPassword = GameObjectFactory.CreateInputField(_signUpMain.transform, Vector2.zero, new Vector2(350f, 25f), "PasswordNameInput", true);
			GameObjectFactory.CreateSingleText(((Component)_signUpPassword).transform, "PasswordText", "Password:", val, new Vector2(350f, 25f), Color.white, (TextFont)0);
			_signUpConfirm = GameObjectFactory.CreateInputField(_signUpMain.transform, Vector2.zero, new Vector2(350f, 25f), "ConfirmNameInput", true);
			GameObjectFactory.CreateSingleText(((Component)_signUpConfirm).transform, "ConfirmText", "Confirm:", new Vector2(0.65f, 0f), new Vector2(350f, 25f), Color.white, (TextFont)0);
			GameObjectFactory.CreateCustomButton(_signUpMain.transform, Vector2.zero, new Vector2(225f, 45f), "Sign Up", "SubmitSignUpButton", (Action)OnSubmitSignUp);
			_fatHelpText = GameObjectFactory.CreateSingleText(_helpMain.transform, "FatTextBox", GetFatHelpText(), Color.white, (TextFont)0);
			_fatHelpText.fontSize = 26f;
			_fatHelpText.alignment = (TextAlignmentOptions)264;
			_fatHelpText.margin = Vector4.op_Implicit(new Vector2(0f, 40f));
			_fatHelpText.lineSpacing = 5f;
			_fatHelpText.paragraphSpacing = 50f;
			_fatHelpText.rectTransform.sizeDelta = new Vector2(1250f, 600f);
			GameObjectFactory.CreateCustomButton(_helpMain.transform, Vector2.zero, new Vector2(225f, 45f), "Keybinds", "KeybindsButton", (Action)OnKeybindsButtonPress);
			_loadingIcon = GameObjectFactory.CreateLoadingIcon(_loadingMain.transform, Vector2.zero, Vector2.one * 64f, AssetManager.GetSprite("toottally128.png"), false, "LoadingIcon");
			_loadingIcon.Show();
			_loadingIcon.StartRecursiveAnimation();
			_leftKeybindsText = GameObjectFactory.CreateSingleText(_keybindsMain.transform, "KeybindLeftTextBox", GetTrombuddiesText() + GetSongMenuText() + GetSpectatorModeText(), Color.white, (TextFont)0);
			_leftKeybindsText.margin = Vector4.op_Implicit(new Vector2(200f, 60f));
			_rightKeybindsText = GameObjectFactory.CreateSingleText(_keybindsMain.transform, "KeybindRightTextBox", GetSongOrganizerText(), Color.white, (TextFont)0);
			_rightKeybindsText.margin = Vector4.op_Implicit(new Vector2(0f, 60f));
			_rightKeybindsText.lineSpacing = (_leftKeybindsText.lineSpacing = 5f);
			TMP_Text rightKeybindsText = _rightKeybindsText;
			TMP_Text leftKeybindsText = _leftKeybindsText;
			TextAlignmentOptions alignment = (TextAlignmentOptions)257;
			leftKeybindsText.alignment = (TextAlignmentOptions)257;
			rightKeybindsText.alignment = alignment;
		}

		private void OnSubmitLogin()
		{
			ChangePage(_loadingMain);
			TootTallyNotifManager.DisplayNotif("Sending login info... Please wait.", 6f);
			((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.GetLoginToken(_loginUsername.text, _loginPassword.text, (Action<LoginToken>)delegate(LoginToken token)
			{
				if (token.token == "")
				{
					TootTallyNotifManager.DisplayError("Username or password wrong... Try logging in again.", 6f);
					ReturnPage("TootTally Login");
				}
				else
				{
					((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.GetUserFromToken(token.token, (Action<User>)delegate(User user)
					{
						ReturnPage("TootTally Login");
						if (user == null)
						{
							TootTallyNotifManager.DisplayError("Couldn't get user info... Please contact TootTally's moderator on discord.", 6f);
						}
						else
						{
							TootTallyNotifManager.DisplayNotif("Login with " + user.username + " successful!", 6f);
							TootTallyUser.OnUserLogin(user);
							Hide();
						}
					}));
				}
			}));
		}

		private void OnLoginButtonClick()
		{
			_titleText.text = "TootTally Login";
			ChangePage(_loginMain);
		}

		private void OnSubmitSignUp()
		{
			if (!IsValidUsername(_signUpUsername.text))
			{
				TootTallyNotifManager.DisplayNotif("Please enter a valid Username.", 6f);
				return;
			}
			if (!IsValidPassword(_signUpPassword.text))
			{
				if (_signUpPassword.text.Length <= 5)
				{
					TootTallyNotifManager.DisplayNotif("Password has to be at least 5 characters long.", 6f);
				}
				else
				{
					TootTallyNotifManager.DisplayNotif("Please enter a valid Password.", 6f);
				}
				return;
			}
			if (_signUpPassword.text != _signUpConfirm.text)
			{
				_signUpPassword.text = "";
				_signUpConfirm.text = "";
				TootTallyNotifManager.DisplayError("Passwords did not match! Type your password again.", 6f);
				return;
			}
			TootTallyNotifManager.DisplayNotif("Sending sign up request... Please wait.", 6f);
			ChangePage(_loadingMain);
			((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.SignUpRequest(_signUpUsername.text, _signUpPassword.text, _signUpConfirm.text, (Action<bool>)delegate(bool isValid)
			{
				if (isValid)
				{
					TootTallyNotifManager.DisplayNotif("Getting new user info...", 6f);
					((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.GetLoginToken(_signUpUsername.text, _signUpPassword.text, (Action<LoginToken>)delegate(LoginToken token)
					{
						if (token.token != "")
						{
							((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.GetUserFromToken(token.token, (Action<User>)delegate(User user)
							{
								if (user != null)
								{
									TootTallyNotifManager.DisplayNotif("Login with " + user.username + " successful!", 6f);
									TootTallyUser.OnUserLogin(user);
									Plugin.Instance.APIKey.Value = user.api_key;
									Hide();
								}
								else
								{
									TootTallyNotifManager.DisplayWarning("Unexpected Error Occured...", 6f);
									ReturnPage("TootTally Sign-up");
								}
							}));
						}
						else
						{
							TootTallyNotifManager.DisplayWarning("Unexpected Error Occured...", 6f);
							ReturnPage("TootTally Sign-up");
						}
					}));
				}
				else
				{
					TootTallyNotifManager.DisplayWarning("Username or password denied by server.", 6f);
					ReturnPage("TootTally Sign-up");
				}
			}));
		}

		private bool IsValidUsername(string username)
		{
			return username != "" && !username.ToLower().Contains("username");
		}

		private bool IsValidPassword(string password)
		{
			return !password.ToLower().Contains("password") && password.Length > 5 && !password.ToLower().Contains(_signUpUsername.text);
		}

		private void OnSignUpButtonClick()
		{
			_titleText.text = "TootTally Sign-up";
			ChangePage(_signUpMain);
		}

		private void OnDontShowAgainClick()
		{
			Hide();
			Plugin.Instance.ShowLoginPanel.Value = false;
		}

		private void OnLogoButtonClick(LogoNames logoName)
		{
			switch (logoName)
			{
			case LogoNames.Question:
				_titleText.text = "";
				ChangePage(_helpMain);
				break;
			case LogoNames.TootTally:
				Application.OpenURL("https://toottally.com/");
				break;
			case LogoNames.Patreon:
				Application.OpenURL("https://patreon.com/TootTally");
				break;
			case LogoNames.Twitter:
				Application.OpenURL("https://twitter.com/TootTally");
				break;
			case LogoNames.Discord:
				Application.OpenURL("https://discord.gg/9jQmVEDVTp");
				break;
			}
		}

		private void OnKeybindsButtonPress()
		{
			_titleText.text = "Keybinds";
			ChangePage(_keybindsMain);
		}

		private void ChangePage(GameObject targetPage)
		{
			_previousPage = _activePage;
			_activePage = targetPage;
			_previousPage.SetActive(false);
			_activePage.SetActive(true);
		}

		private void ReturnPage(string titleText = "")
		{
			if ((Object)(object)_previousPage != (Object)null)
			{
				if (titleText == "")
				{
					_titleText.text = "Welcome To Toottally";
				}
				else
				{
					_titleText.text = titleText;
				}
				ChangePage(_previousPage);
				_previousPage = null;
			}
		}

		private void ReturnToHomePage()
		{
			if ((Object)(object)_activePage == (Object)(object)_menuMain)
			{
				Hide();
				return;
			}
			_titleText.text = "Welcome To Toottally";
			ChangePage(_menuMain);
			_previousPage = null;
		}

		public void ApplyTheme()
		{
		}

		public void Show()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			_gameObject.SetActive(true);
			_mainPanelBG.transform.localScale = Vector2.op_Implicit(Vector2.zero);
			TootTallyAnimationManager.AddNewScaleAnimation(_mainPanelBG, Vector3.one, 1f, GetSecondDegreeAnimation(1.5f), (Action<GameObject>)null);
		}

		public void Hide()
		{
			//IL_001a: 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_0049: Expected O, but got Unknown
			LoadingIcon loadingIcon = _loadingIcon;
			if (loadingIcon != null)
			{
				loadingIcon.StopRecursiveAnimation(true);
			}
			TootTallyAnimationManager.AddNewScaleAnimation(_mainPanelBG, Vector2.zero, 0.7f, new SecondDegreeDynamicsAnimation(1.75f, 0.75f, 1f), (Action<GameObject>)delegate
			{
				_gameObject.SetActive(false);
			});
		}

		public static SecondDegreeDynamicsAnimation GetSecondDegreeAnimation(float speedMult = 1f)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			return new SecondDegreeDynamicsAnimation(speedMult, 0.75f, 1.15f);
		}

		public string GetFatHelpText()
		{
			return "<size=62><b>CURIOUS ABOUT ACCOUNTS?</b></size>\n\nCreating an account with us is completely optional and we want you to enjoy TootTally your way. if you decide to sign up, you'll gain access to having your scores saved in the TootTally Database, Twitch Integration, Multiplayer and Tournaments. It's a great way to enhance your experience, keep track of your progress and get to know the community a little better.\n\nIf you prefer to toot alone, that's cool too! You can still enjoy the core features of TootTally that makes Trombone Champ an awesome addition to your rhythm game experience. Feel free to skip for now - you can always sign up later inside of TootTally Settings or on our Website.\nHappy Tooting!";
		}

		public string GetTrombuddiesText()
		{
			return "<size=48><b>Trombuddies</b></size>\n\tF2 - Toggle Trombuddies\n\tF3 - Toggle show all users\n\tF4 - Toggle show friends only\n\t?? - Secret\n\n";
		}

		public string GetSongMenuText()
		{
			return "<size=48><b>Song Select Screen</b></size>\n\tCtrl+R - Reload song list\n\tF5 - Random Song\n\tF8 - Twitch Requests\n\n";
		}

		public string GetSpectatorModeText()
		{
			return "<size=48><b>Spectator Mode</b></size>\n\tShift+Esc - Refresh Song List\n\n";
		}

		public string GetSongOrganizerText()
		{
			return "<size=48><b>Song Organizer</b></size>\n\tCtrl+F - Search for songs\n\n";
		}
	}
	public static class TootTallyUser
	{
		public static User userInfo = new User
		{
			allowSubmit = false,
			id = 0,
			username = "Guest"
		};

		private static List<Message> _messagesReceived;

		private static TootTallyLoginPanel _loginPanel;

		private static bool _hasGreetedUser;

		[HarmonyPatch(typeof(HomeController), "Start")]
		[HarmonyPostfix]
		public static void InitializeUser()
		{
			if (_messagesReceived == null)
			{
				_messagesReceived = new List<Message>();
			}
			if (Plugin.GetAPIKey == "SignUpOnTootTally.com" || Plugin.GetAPIKey == "")
			{
				if (Plugin.Instance.ShowLoginPanel.Value)
				{
					OpenLoginPanel();
				}
			}
			else
			{
				if (userInfo.id != 0)
				{
					return;
				}
				((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.GetUserFromAPIKey(Plugin.GetAPIKey, (Action<User>)delegate(User user)
				{
					if (user.id == 0 && Plugin.Instance.ShowLoginPanel.Value)
					{
						OpenLoginPanel();
					}
					else
					{
						OnUserLogin(user);
					}
				}));
			}
		}

		[HarmonyPatch(typeof(LevelSelectController), "Start")]
		[HarmonyPostfix]
		public static void DisplayReceivedMessaged()
		{
			if (userInfo.id == 0)
			{
				return;
			}
			if (!_hasGreetedUser)
			{
				TootTallyNotifManager.DisplayNotif("Welcome, " + userInfo.username + "!", 9f);
				_hasGreetedUser = true;
			}
			((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.GetMessageFromAPIKey(Plugin.GetAPIKey, (Action<APIMessages>)delegate(APIMessages messages)
			{
				Plugin.LogInfo("Messages received: " + messages.results.Count);
				foreach (Message message in messages.results)
				{
					if (_messagesReceived.FindAll((Message m) => m.sent_on == message.sent_on).Count == 0)
					{
						_messagesReceived.Add(message);
						TootTallyNotifManager.DisplayNotif("<size=14>From:" + message.author + " (" + message.sent_on + ")</size>\n" + message.message, 16f);
					}
				}
			}));
		}

		public static void OnUserLogin(User user)
		{
			userInfo = user;
			if (userInfo.api_key != null && userInfo.api_key != "")
			{
				Plugin.Instance.APIKey.Value = userInfo.api_key;
			}
			if (userInfo.id == 0)
			{
				userInfo.allowSubmit = false;
				return;
			}
			((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.SendModInfo(Plugin.Instance.APIKey.Value, Chainloader.PluginInfos, (Action<bool>)delegate(bool allowSubmit)
			{
				userInfo.allowSubmit = allowSubmit;
			}));
			UserStatusManager.SetUserStatus(UserStatusManager.UserStatus.Online);
		}

		public static void OpenLoginPanel()
		{
			if (_loginPanel == null)
			{
				_loginPanel = new TootTallyLoginPanel();
			}
			_loginPanel.Show();
		}
	}
	public class UserStatusManager : MonoBehaviour
	{
		public enum UserStatus
		{
			Online,
			Idle,
			MainMenu,
			BrowsingSongs,
			Playing,
			WatchingReplay,
			Spectating,
			NotConnected
		}

		private const float DEFAULT_TIMER_VALUE = 5f;

		private static float _timer;

		private static bool _isTimerReady;

		private static UserStatus _currentStatus;

		private static UserStatus _lastStatus;

		private static UserStatus _preIdleStatus;

		private static int _heartbeatCount;

		private static bool _isInitialized;

		private void Awake()
		{
			_currentStatus = UserStatus.NotConnected;
			ResetTimer(autoStart: false);
			_isInitialized = true;
			_heartbeatCount = 0;
		}

		private void Update()
		{
			if (_currentStatus != UserStatus.NotConnected && _isInitialized)
			{
				_timer -= Time.unscaledDeltaTime;
				if (_isTimerReady && _timer < 0f)
				{
					OnTimerEnd();
				}
			}
		}

		public static void SetUserStatus(UserStatus newStatus)
		{
			if (_isInitialized && TootTallyUser.userInfo.id != 0)
			{
				_currentStatus = newStatus;
				OnTimerEnd();
				if (newStatus != UserStatus.Idle)
				{
					ResetTimerAndWakeUpIfIdle();
				}
			}
		}

		public static void ResetTimerAndWakeUpIfIdle()
		{
			_heartbeatCount = 0;
			if (_currentStatus == UserStatus.Idle)
			{
				SetUserStatus(_preIdleStatus);
			}
		}

		private static void OnTimerEnd()
		{
			_isTimerReady = false;
			((MonoBehaviour)Plugin.Instance).StartCoroutine((IEnumerator)TootTallyAPIService.SendUserStatus(Plugin.GetAPIKey, (int)_currentStatus, (Action)OnHeartBeatRequestResponse));
		}

		public static void OnHeartBeatRequestResponse()
		{
			ResetTimer();
			HandleHeartBeatCounter();
		}

		public static void HandleHeartBeatCounter()
		{
			if (ShouldResetCounter())
			{
				_heartbeatCount = 0;
			}
			else
			{
				_heartbeatCount++;
				if (_heartbeatCount >= 60)
				{
					_preIdleStatus = _currentStatus;
					SetUserStatus(UserStatus.Idle);
				}
			}
			_lastStatus = _currentStatus;
		}

		public static void ResetTimer()
		{
			_timer = ((_currentStatus == UserStatus.Idle) ? 40f : 5f);
			_isTimerReady = true;
		}

		public static bool ShouldResetCounter()
		{
			return _lastStatus != _currentStatus || _currentStatus == UserStatus.Playing || _currentStatus == UserStatus.WatchingReplay;
		}

		public static void ResetTimer(bool autoStart)
		{
			_timer = 5f;
			_isTimerReady = autoStart;
		}

		public static void StartTimer()
		{
			_isTimerReady = true;
		}
	}
	public static class UserStatusUpdater
	{
		[HarmonyPatch(typeof(HomeController), "Start")]
		[HarmonyPostfix]
		public static void SetHomeScreenUserStatus()
		{
			UserStatusManager.SetUserStatus(UserStatusManager.UserStatus.MainMenu);
		}

		[HarmonyPatch(typeof(CharSelectController), "Start")]
		[HarmonyPostfix]
		public static void SetCharScreenUserStatus()
		{
			UserStatusManager.SetUserStatus(UserStatusManager.UserStatus.MainMenu);
		}

		[HarmonyPatch(typeof(LevelSelectController), "Start")]
		[HarmonyPostfix]
		public static void SetLevelSelectUserStatusOnAdvanceSongs()
		{
			UserStatusManager.SetUserStatus(UserStatusManager.UserStatus.BrowsingSongs);
		}

		[HarmonyPatch(typeof(LevelSelectController), "advanceSongs")]
		[HarmonyPostfix]
		public static void SetLevelSelectUserStatus()
		{
			UserStatusManager.ResetTimerAndWakeUpIfIdle();
		}

		[HarmonyPatch(typeof(GameController), "startSong")]
		[HarmonyPostfix]
		public static void SetPlayingUserStatus()
		{
			UserStatusManager.SetUserStatus(UserStatusManager.UserStatus.Playing);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TootTallyAccounts";

		public const string PLUGIN_NAME = "TootTallyAccounts";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}