Ejemplo n.º 1
0
        protected void CreateUI()
        {
            try
            {
                _mainMenuViewController = Resources.FindObjectsOfTypeAll <MainMenuViewController>().First();
                _mainMenuRectTransform  = _mainMenuViewController.transform as RectTransform;

                _mockPartyViewController = new MockPartyViewController();

                if (Config.Instance.AutoStartLobby)
                {
                    SteamAPI.CreateLobby(!Config.Instance.IsPublic);
                }

                AvatarController.LoadAvatars();
                SongListUtils.Initialize();
                MultiplayerListing.Init();
                MultiplayerLobby.Init();
                WaitingMenu.Init();
                CreateMainMenuButton();
                CreateSettingsMenu();
            }
            catch (Exception e)
            {
                Logger.Error($"Unable to create UI! Exception: {e}");
            }
        }
Ejemplo n.º 2
0
        private static void ReadyUp(IBeatmapLevel song)
        {
            if (queuedSong != null || (queuedSong == null && song == null))
            {
                return;
            }
            if (queuedSong == null && song != null)
            {
                queuedSong = song;
                if (autoReady)
                {
                    PracticeSettings pSettings = null;
                    if (SteamAPI.GetSongOffset() > 0f)
                    {
                        pSettings = new PracticeSettings();
                        float offsetTime = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds() - timeRequestedToLaunch;
                        // add 5 seconds to it because that's about how long it takes to launch a song
                        pSettings.startSongTime = SteamAPI.GetSongOffset() + offsetTime + 5f;
                        timeRequestedToLaunch   = 0;
                    }

                    SongListUtils.StartSong(song, SteamAPI.GetSongDifficulty(), SteamAPI.GetGameplayModifiers(), pSettings);
                }
                else
                {
                    SteamAPI.SetReady();
                    PreviewPlayer.CrossfadeTo(song.previewAudioClip, song.previewStartTime, song.previewDuration);
                }
            }
        }
        private static IEnumerator ProcessSongRequest(int index = -1)
        {
            if (FinalRequestQueue.Count > 0)
            {
                SongRequest request = index == -1 ? FinalRequestQueue.First() : FinalRequestQueue.ElementAt(index);
                JSONObject  song    = request.song;
                FinalRequestQueue.Remove(request);
                UpdateRequestButton();

                bool   retried = false;
                string songIndex = song["version"], songName = song["songName"].Value;
                string currentSongDirectory = $"{Environment.CurrentDirectory}\\CustomSongs\\{songIndex}";
                string songHash             = ((string)song["hashMd5"]).ToUpper();
retry:
                CustomLevel[] levels = SongLoader.CustomLevels.Where(l => l.levelID.StartsWith(songHash)).ToArray();
                if (levels.Length == 0)
                {
                    Utilities.EmptyDirectory(".requestcache", false);

                    if (Directory.Exists(currentSongDirectory))
                    {
                        Utilities.EmptyDirectory(currentSongDirectory, true);
                        Plugin.Log($"Deleting {currentSongDirectory}");
                    }

                    string localPath = $"{Environment.CurrentDirectory}\\.requestcache\\{songIndex}.zip";
                    yield return(Utilities.DownloadFile(song["downloadUrl"], localPath));

                    yield return(Utilities.ExtractZip(localPath, currentSongDirectory));

                    yield return(SongListUtils.RefreshSongs(false, false, true));

                    Utilities.EmptyDirectory(".requestcache", true);
                    levels = SongLoader.CustomLevels.Where(l => l.levelID.StartsWith(songHash)).ToArray();
                }
                else
                {
                    Plugin.Log($"Song {songName} already exists!");
                }

                if (levels.Length > 0)
                {
                    Plugin.Log($"Scrolling to level {levels[0].levelID}");
                    if (!SongListUtils.ScrollToLevel(levels[0].levelID) && !retried)
                    {
                        retried = true;
                        goto retry;
                    }
                }
                else
                {
                    Plugin.Log("Failed to find new level!");
                }
                _songRequestMenu.Dismiss();
                SongRequestDequeued?.Invoke(song);
            }
        }
Ejemplo n.º 4
0
        public static void RefreshData(LevelSO song = null)
        {
            try
            {
                if (queuedSong == null)
                {
                    if (song == null)
                    {
                        song = SongListUtils.GetInstalledSong();
                    }
                    Logger.Debug($"Refresh Waiting Menu data - Song is {(song != null ? "not" : "")} loaded");
                    if (song != null)
                    {
                        level.text = $"Queued: { song.songName} by { song.songAuthorName }";
                        if (song is CustomLevel)
                        {
                            SongLoader.Instance.LoadAudioClipForLevel((CustomLevel)song, (customLevel) =>
                            {
                                Logger.Debug($"Loaded audio Clip for {song.songName}");
                                ReadyUp(customLevel);
                            });
                        }
                        else
                        {
                            ReadyUp(song);
                        }
                    }
                    else if (!downloading)
                    {
                        level.text = $"Downloading: { SteamAPI.GetSongName()}";

                        Logger.Debug($"We do not have the song in our library, lets start downloading it.");
                        downloading = true;
                        Instance.StartCoroutine(Utils.SongDownloader.Instance.DownloadSong(SteamAPI.GetSongId(), LevelDownloadProgress, LevelDownloaded));
                    }
                }
                if (Instance && Instance.isActiveAndEnabled)
                {
                    Dictionary <string, float> status = Controllers.PlayerController.Instance.GetConnectedPlayerDownloadStatus();
                    middleViewController.Data.Clear();
                    foreach (KeyValuePair <string, float> user in status.OrderBy(u => u.Value))
                    {
                        CustomCellInfo cell = new CustomCellInfo(user.Key, user.Value == -1f ? "FAILED TO DOWNLOAD": user.Value == 1f ? "Ready" : $"Downloading song ${(int) Math.Round(user.Value * 100, 0)}%", user.Value == 1f ? Sprites.checkmarkIcon : Sprites.crossIcon);
                        middleViewController.Data.Add(cell);
                    }
                    middleViewController._customListTableView.ReloadData();
                    middleViewController._customListTableView.ScrollToRow(0, false);
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
Ejemplo n.º 5
0
 public static void LevelDownloaded(string hash)
 {
     try
     {
         downloading = false;
         IBeatmapLevel song = SongListUtils.GetInstalledSong(hash.ToUpper());
         RefreshData(song);
     } catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Ejemplo n.º 6
0
        protected void CreateUI()
        {
            try
            {
                _mainMenuViewController = Resources.FindObjectsOfTypeAll <MainMenuViewController>().First();
                _mainMenuViewController.didFinishEvent += (sender, result) =>
                {
                    Logger.Debug($"finish \"{result}\"");
                    if (result == MainMenuViewController.MenuButton.Party)
                    {
                        try
                        {
                            _mockPartyViewController = new MockPartyViewController();
                        } catch (Exception e)
                        {
                            Logger.Error(e);
                        }
                    }
                };
                _mainMenuRectTransform = _mainMenuViewController.transform as RectTransform;

                if (Config.Instance.AutoStartLobby)
                {
                    SteamAPI.CreateLobby(!Config.Instance.IsPublic);
                }
                try
                {
                    AvatarController.LoadAvatars();
                } catch (Exception e)
                {
                    Logger.Error($"Unable to load avatars! Exception: {e}");
                }
                SongListUtils.Initialize();
                MultiplayerListing.Init();
                MultiplayerLobby.Init();
                WaitingMenu.Init();
                CreateSettingsMenu();
                CreateMainMenuButton();
            }
            catch (Exception e)
            {
                Logger.Error($"Unable to create UI! Exception: {e}");
            }
        }
Ejemplo n.º 7
0
 public static void RequestPlay(GameplayModifiers gameplayModifiers)
 {
     if (IsHost())
     {
         try
         {
             Logger.Debug($"update the current screen to the waiting screen while people download the song");
             LevelSO song = SongListUtils.GetInstalledSong();
             if (song != null)
             {
                 setLobbyStatus("Loading " + song.songName + " by " + song.songAuthorName);
             }
             _lobbyInfo.GameplayModifiers = gameplayModifiers;
             _lobbyInfo.Screen            = LobbyInfo.SCREEN_TYPE.WAITING;
             SendLobbyInfo(true);
         } catch (Exception e)
         {
             Logger.Error(e);
         }
     }
 }
        public static void OnLoad()
        {
            _levelSelectionFlowCoordinator = Resources.FindObjectsOfTypeAll <SoloFreePlayFlowCoordinator>().First();
            if (_levelSelectionFlowCoordinator)
            {
                _levelSelectionNavigationController = _levelSelectionFlowCoordinator.GetPrivateField <DismissableNavigationController>("_navigationController");
            }

            if (_levelSelectionNavigationController)
            {
                if (_songRequestMenu == null)
                {
                    _songRequestMenu = BeatSaberUI.CreateCustomMenu <CustomMenu>("Song Request Queue");
                    _songRequestListViewController = BeatSaberUI.CreateViewController <RequestBotListViewController>();
                    _songRequestMenu.SetMainViewController(_songRequestListViewController, true);
                }

                _requestButton = BeatSaberUI.CreateUIButton(_levelSelectionNavigationController.rectTransform, "QuitButton", new Vector2(60f, 36.8f),
                                                            new Vector2(15.0f, 5.5f), () => { _requestButton.interactable = false; _songRequestMenu.Present(); _requestButton.interactable = true; }, "Song Requests");

                _requestButton.gameObject.GetComponentInChildren <TextMeshProUGUI>().enableWordWrapping = false;
                _requestButton.SetButtonTextSize(2.0f);
                _requestButton.interactable = FinalRequestQueue.Count > 0;
                _requestButton.gameObject.GetComponentInChildren <Image>().color = FinalRequestQueue.Count > 0 ? Color.green : Color.red;
                BeatSaberUI.AddHintText(_requestButton.transform as RectTransform, $"{(!Config.Instance.SongRequestBot ? "To enable the song request bot, look in the Enhanced Twitch Chat settings menu." : "Manage the current request queue")}");
                Plugin.Log("Created request button!");
            }

            SongListUtils.Initialize();

            if (Instance)
            {
                return;
            }
            new GameObject("EnhancedTwitchChatRequestBot").AddComponent <RequestBot>();
        }
Ejemplo n.º 9
0
        public void OnLobbyDataUpdate(LobbyDataUpdate_t pCallback)
        {
            if (pCallback.m_ulSteamIDLobby == pCallback.m_ulSteamIDMember)
            {
                LobbyInfo info = new LobbyInfo(SteamMatchmaking.GetLobbyData(new CSteamID(pCallback.m_ulSteamIDLobby), "LOBBY_INFO"));

                if (pCallback.m_ulSteamIDLobby == 0)
                {
                    return;
                }
                Logger.Debug($"Received: {info.ToString()}");
                if (pCallback.m_ulSteamIDLobby == SteamAPI.getLobbyID().m_SteamID)
                {
                    SteamAPI.UpdateLobbyInfo(info);
                    if (DidScreenChange(info.Screen, LobbyInfo.SCREEN_TYPE.WAITING))
                    {
                        currentScreen = info.Screen;
                        Logger.Debug($"Song has been selected, going to the waiting screen");
                        WaitingMenu.Instance.Present();
                    }
                    else if (DidScreenChange(info.Screen, LobbyInfo.SCREEN_TYPE.MENU))
                    {
                        currentScreen = info.Screen;
                        Logger.Debug($"Song has finished, updating state to menu");
                        GameController.Instance.SongFinished(null, null, null, null);
                    }
                    else if (DidScreenChange(info.Screen, LobbyInfo.SCREEN_TYPE.PLAY_SONG))
                    {
                        currentScreen = info.Screen;
                        Logger.Debug($"Host requested to play the current song {info.CurrentSongId}");

                        LevelSO song = SongListUtils.GetInstalledSong();
                        if (SteamAPI.IsHost())
                        {
                            SteamAPI.setLobbyStatus("Playing " + song.songName + " by " + song.songAuthorName);
                        }

                        SteamAPI.ClearPlayerReady(new CSteamID(SteamAPI.GetUserID()), true);
                        SongListUtils.StartSong(song, SteamAPI.GetSongDifficulty(), info.GameplayModifiers);
                    }
                }
                else
                {
                    SteamAPI.SetOtherLobbyData(pCallback.m_ulSteamIDLobby, info);
                }
            }
            else
            {
                string status = SteamMatchmaking.GetLobbyMemberData(new CSteamID(pCallback.m_ulSteamIDLobby), new CSteamID(pCallback.m_ulSteamIDMember), "STATUS");
                if (status == "DISCONNECTED")
                {
                    SteamAPI.DisconnectPlayer(pCallback.m_ulSteamIDMember);
                }
                else if (status.StartsWith("KICKED"))
                {
                    ulong playerId = Convert.ToUInt64(status.Substring(7));
                    if (playerId != 0 && playerId == SteamAPI.GetUserID())
                    {
                        SteamAPI.Disconnect();
                    }
                }
            }
        }