From 5d90bec6454367df746efb3cb400677b858802e4 Mon Sep 17 00:00:00 2001 From: Zingabopp Date: Mon, 6 Apr 2020 23:49:44 -0500 Subject: [PATCH] Improved GetUserInfo --- BeatSaberMultiplayer/Client.cs | 4 ++-- BeatSaberMultiplayer/Plugin.cs | 21 ++++++++++++------- .../ServerHubFlowCoordinator.cs | 2 +- BeatSaberMultiplayer/UI/PluginUI.cs | 3 ++- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/BeatSaberMultiplayer/Client.cs b/BeatSaberMultiplayer/Client.cs index c8ac7722..2e378a32 100644 --- a/BeatSaberMultiplayer/Client.cs +++ b/BeatSaberMultiplayer/Client.cs @@ -153,7 +153,7 @@ public void Awake() instance = this; DontDestroyOnLoad(this); GetUserInfo.UpdateUserInfo(); - playerInfo = new PlayerInfo(GetUserInfo.GetUserName(), GetUserInfo.GetUserID()); + playerInfo = new PlayerInfo(Plugin.Username, Plugin.UserId); NetPeerConfiguration Config = new NetPeerConfiguration("BeatSaberMultiplayer") { MaximumHandshakeAttempts = 2, AutoFlushSendQueue = false }; networkClient = new NetClient(Config); @@ -193,7 +193,7 @@ public void Connect(string IP, int Port) byte[] version = new byte[4] { (byte)assemblyVersion.Major, (byte)assemblyVersion.Minor, (byte)assemblyVersion.Build, (byte)assemblyVersion.Revision }; outMsg.Write(version); - playerInfo = new PlayerInfo(GetUserInfo.GetUserName(), GetUserInfo.GetUserID()); + playerInfo = new PlayerInfo(Plugin.Username, Plugin.UserId); playerInfo.AddToMessage(outMsg); Plugin.log.Debug($"Connecting to {ip}:{port} with player name \"{playerInfo.playerName}\" and ID {playerInfo.playerId}"); diff --git a/BeatSaberMultiplayer/Plugin.cs b/BeatSaberMultiplayer/Plugin.cs index 158ed232..8ae32f34 100644 --- a/BeatSaberMultiplayer/Plugin.cs +++ b/BeatSaberMultiplayer/Plugin.cs @@ -39,6 +39,9 @@ public class Plugin private static string joinSecret; public static bool DownloaderExists { get; private set; } + public static string Username; + public static ulong UserId; + public static void LogLocation(string message, [CallerFilePath] string memberPath = "", [CallerMemberName] string memberName = "", @@ -71,17 +74,11 @@ public void Init(IPA.Logging.Logger logger, PluginMetadata pluginMetadata) PluginVersion = $"{v.Major}.{v.Minor}.{v.Build}"; log.Info($"{PluginMetadata.Name} v{PluginVersion} initialized. Current culture is {CultureInfo.CurrentCulture.Name}"); } + [OnStart] public void OnApplicationStart() { instance = this; - var votingMeta = PluginManager.GetPluginFromId("BeatSaverVoting"); - if (votingMeta != null) - { - log.Error($"votingMeta is not null: {votingMeta.File}"); - } - else - log.Warn($"votingMeta is null."); //BS_Utils.Utilities.BSEvents.OnLoad(); BS_Utils.Utilities.BSEvents.menuSceneLoadedFresh += MenuSceneLoadedFresh; BS_Utils.Utilities.BSEvents.menuSceneLoaded += MenuSceneLoaded; @@ -158,12 +155,22 @@ public void OnActivityJoin(object sender, string secret) } } + public static bool ReadUserInfo() + { + UserId = GetUserInfo.GetUserID(); + Username = GetUserInfo.GetUserName(); + if (UserId != 0) + return true; + return false; + } + private void MenuSceneLoadedFresh() { //ModelSaberAPI.HashAllAvatars(); PluginUI.OnLoad(); InGameOnlineController.OnLoad(); SpectatingController.OnLoad(); + BS_Utils.Gameplay.GetUserInfo.UpdateUserInfo(); GetUserInfo.UpdateUserInfo(); if (joinAfterRestart) { diff --git a/BeatSaberMultiplayer/UI/FlowCoordinators/ServerHubFlowCoordinator.cs b/BeatSaberMultiplayer/UI/FlowCoordinators/ServerHubFlowCoordinator.cs index 10d6972e..815738eb 100644 --- a/BeatSaberMultiplayer/UI/FlowCoordinators/ServerHubFlowCoordinator.cs +++ b/BeatSaberMultiplayer/UI/FlowCoordinators/ServerHubFlowCoordinator.cs @@ -345,7 +345,7 @@ public void GetRooms() byte[] version = new byte[4] { (byte)assemblyVersion.Major, (byte)assemblyVersion.Minor, (byte)assemblyVersion.Build, (byte)assemblyVersion.Revision }; outMsg.Write(version); - new PlayerInfo(GetUserInfo.GetUserName(), GetUserInfo.GetUserID()).AddToMessage(outMsg); + new PlayerInfo(Plugin.Username, Plugin.UserId).AddToMessage(outMsg); Plugin.log.Debug($"Connecting to {ip}:{port}..."); diff --git a/BeatSaberMultiplayer/UI/PluginUI.cs b/BeatSaberMultiplayer/UI/PluginUI.cs index 1d136d68..df5f90d1 100644 --- a/BeatSaberMultiplayer/UI/PluginUI.cs +++ b/BeatSaberMultiplayer/UI/PluginUI.cs @@ -156,6 +156,7 @@ private void CreateOnlineButton() { try { + Plugin.ReadUserInfo(); SetLobbyDiscordActivity(); MainFlowCoordinator mainFlow = Resources.FindObjectsOfTypeAll().First(); @@ -166,7 +167,7 @@ private void CreateOnlineButton() _noUserInfoWarning = Instantiate(dialogOrig.gameObject).GetComponent(); } - if (GetUserInfo.GetUserID() == 0 && string.IsNullOrWhiteSpace(GetUserInfo.GetUserName()) || GetUserInfo.GetUserID() == 0) + if (Plugin.UserId == 0 && string.IsNullOrWhiteSpace(Plugin.Username) || Plugin.UserId == 0) { _noUserInfoWarning.Init("Invalid username and ID", $"Your username and ID are invalid\nMake sure you are logged in", "Go back", "Continue anyway", (selectedButton) =>