Пример #1
0
        IEnumerator InitializeAvatarController()
        {
            if (!defaultAvatarInstance.IsLoaded)
            {
                Logger.Debug("Waiting for avatar to load");
                yield return(new WaitWhile(delegate() { return !defaultAvatarInstance.IsLoaded; }));
            }
            else
            {
                yield return(null);
            }

            Logger.Debug("Spawning avatar");
            _centerAdjust = FindObjectOfType <VRCenterAdjust>();

            avatar = AvatarSpawner.SpawnAvatar(defaultAvatarInstance, this);

            playerNameText = CreateWorldText(transform, "Loading");
            playerNameText.rectTransform.anchoredPosition3D = new Vector3(0f, 0.25f, 0f);
            playerNameText.alignment = TextAlignmentOptions.Center;
            playerNameText.fontSize  = 2.5f;

            avatar.GameObject.transform.SetParent(_centerAdjust.transform, false);
            transform.SetParent(_centerAdjust.transform, false);
        }
Пример #2
0
        void Update()
        {
            uint size;

            try
            {
                while (SteamNetworking.IsP2PPacketAvailable(out size))
                {
                    var      buffer = new byte[size];
                    uint     bytesRead;
                    CSteamID remoteId;
                    if (SteamNetworking.ReadP2PPacket(buffer, size, out bytesRead, out remoteId))
                    {
                        var          message = Encoding.UTF8.GetString(buffer).Replace(" ", "");
                        PlayerPacket info    = new PlayerPacket(message);
                        if (info.playerId != SteamAPI.GetUserID() && SteamAPI.getLobbyID().m_SteamID != 0)
                        {
                            UpsertPlayer(info);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
Пример #3
0
        public void SongFinished(StandardLevelSceneSetupDataSO sender, LevelCompletionResults levelCompletionResults, IDifficultyBeatmap difficultyBeatmap, GameplayModifiers gameplayModifiers)
        {
            try
            {
                if (sender == null || levelCompletionResults == null || difficultyBeatmap == null || gameplayModifiers == null)
                {
                    return;
                }
                Logger.Debug("Finished song: " + levelCompletionResults.levelEndStateType + " - " + levelCompletionResults.songDuration + " - - " + levelCompletionResults.endSongTime);

                PlayerDataModelSO _playerDataModel = Resources.FindObjectsOfTypeAll <PlayerDataModelSO>().First();
                _playerDataModel.currentLocalPlayer.playerAllOverallStatsData.soloFreePlayOverallStatsData.UpdateWithLevelCompletionResults(levelCompletionResults);
                _playerDataModel.Save();
                if (levelCompletionResults.levelEndStateType != LevelCompletionResults.LevelEndStateType.Failed && levelCompletionResults.levelEndStateType != LevelCompletionResults.LevelEndStateType.Cleared)
                {
                    return;
                }

                PlayerDataModelSO.LocalPlayer currentLocalPlayer = _playerDataModel.currentLocalPlayer;
                bool                 cleared              = levelCompletionResults.levelEndStateType == LevelCompletionResults.LevelEndStateType.Cleared;
                string               levelID              = difficultyBeatmap.level.levelID;
                BeatmapDifficulty    difficulty           = difficultyBeatmap.difficulty;
                PlayerLevelStatsData playerLevelStatsData = currentLocalPlayer.GetPlayerLevelStatsData(levelID, difficulty);
                bool                 newHighScore         = playerLevelStatsData.highScore < levelCompletionResults.score;
                playerLevelStatsData.IncreaseNumberOfGameplays();
                if (cleared)
                {
                    playerLevelStatsData.UpdateScoreData(levelCompletionResults.score, levelCompletionResults.maxCombo, levelCompletionResults.fullCombo, levelCompletionResults.rank);
                    Resources.FindObjectsOfTypeAll <PlatformLeaderboardsModel>().First().AddScore(difficultyBeatmap, levelCompletionResults.unmodifiedScore, gameplayModifiers);
                }
            } catch (Exception e)
            {
                Data.Logger.Error(e);
            }
        }
Пример #4
0
        public static void LoadAvatars()
        {
            if (defaultAvatarInstance == null)
            {
                defaultAvatarInstance = CustomAvatar.Plugin.Instance.AvatarLoader.Avatars.FirstOrDefault(x => x.FullPath.ToLower().Contains("template.avatar"));
            }
            Logger.Debug($"Found avatar, isLoaded={defaultAvatarInstance.IsLoaded}");
            if (!defaultAvatarInstance.IsLoaded)
            {
                defaultAvatarInstance.Load(null);
            }

            foreach (CustomAvatar.CustomAvatar avatar in CustomAvatar.Plugin.Instance.AvatarLoader.Avatars)
            {
                Task.Run(() =>
                {
                    string hash;
                    if (CreateMD5FromFile(avatar.FullPath, out hash))
                    {
                        ModelSaberAPI.cachedAvatars.Add(hash, avatar);
                        Logger.Debug("Hashed avatar " + avatar.Name + "! Hash: " + hash);
                    }
                }).ConfigureAwait(false);
            }
        }
Пример #5
0
        public static void Init()
        {
            if (Instance == null)
            {
                Instance             = BeatSaberUI.CreateCustomMenu <CustomMenu>("Waiting for players");
                middleViewController = BeatSaberUI.CreateViewController <ListViewController>();

                Instance.SetMainViewController(middleViewController, true, (firstActivation, type) =>
                {
                    try
                    {
                        if (firstActivation)
                        {
                            level           = middleViewController.CreateText("", new Vector2(BASE.x + 40f, BASE.y));
                            level.alignment = TMPro.TextAlignmentOptions.Center;

                            SteamAPI.SendPlayerPacket(Controllers.PlayerController.Instance._playerInfo);
                        }
                        if (firstInit)
                        {
                            firstInit = false;
                            RefreshData();
                        }
                    } catch (Exception e)
                    {
                        Logger.Error(e);
                    }
                });
            }
        }
Пример #6
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}");
            }
        }
Пример #7
0
 public VoiceListener()
 {
     _thread = new Thread(() =>
     {
         while (!_stopped)
         {
             uint size;
             try
             {
                 while (SteamUser.GetAvailableVoice(out size) == EVoiceResult.k_EVoiceResultOK && size > 1024)
                 {
                     byte[] buffer = new byte[size];
                     uint bytesWritten;
                     if (SteamUser.GetVoice(true, buffer, size, out bytesWritten) == EVoiceResult.k_EVoiceResultOK && bytesWritten > 0)
                     {
                         Data.Steam.SteamAPI.SendVoip(new VoipPacket(buffer));
                     }
                 }
             }
             catch (Exception e)
             {
                 Logger.Error(e);
             }
         }
     });
     _thread.Start();
 }
Пример #8
0
        IEnumerator RunLobbyCleanup()
        {
            yield return(new WaitUntil(delegate() { Data.Logger.Info("waiting for active: " + WaitingMenu.Instance.isActiveAndEnabled); return WaitingMenu.Instance.isActiveAndEnabled; }));

            Logger.Debug("Finished song, doing cleanup");
            WaitingMenu.Instance.Dismiss();
            WaitingMenu.firstInit  = true;
            WaitingMenu.queuedSong = null;
            SongListUtils.InSong   = false;
            SteamAPI.FinishSong();
        }
Пример #9
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);
            }
        }
Пример #10
0
 void BroadcastPlayerPacket()
 {
     try
     {
         UpdatePlayerPacket();
         SteamAPI.SendPlayerPacket(_playerInfo);
     } catch (Exception e)
     {
         Logger.Error(e);
     }
 }
        protected void didSelectLevel(LevelListViewController controller, IBeatmapLevel level)
        {
            Logger.Debug($"level {level.levelID} selected");

            if (!_partyFlowCoordinator || !_partyFlowCoordinator.isActivated)
            {
                toggleButtons(true);
                return;
            }
            toggleButtons(false);
            SteamAPI.SetSong(level.levelID, level.songName);
        }
        private void didSelectBeatmap(BeatmapDifficultyViewController controller, IDifficultyBeatmap beatmap)
        {
            Logger.Debug($"beatmap {beatmap.difficulty} selected");
            if (!_partyFlowCoordinator || !_partyFlowCoordinator.isActivated)
            {
                toggleButtons(true);
                return;
            }

            toggleButtons(false);
            SteamAPI.SetDifficulty((byte)beatmap.difficulty);
        }
Пример #13
0
 public static void LevelDownloaded(string hash)
 {
     try
     {
         downloading = false;
         IBeatmapLevel song = SongListUtils.GetInstalledSong(hash.ToUpper());
         RefreshData(song);
     } catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Пример #14
0
        void Update()
        {
            try
            {
                if (avatar != null && !forcePlayerPacket)
                {
                    if (GameController.TPS < (1f / Time.smoothDeltaTime))
                    {
                        interpolationProgress += Time.deltaTime * GameController.TPS;
                    }
                    else
                    {
                        interpolationProgress = 1f;
                    }
                    if (interpolationProgress > 1f)
                    {
                        interpolationProgress = 1f;
                    }

                    interpHeadPos      = Vector3.Lerp(lastHeadPos, targetHeadPos, interpolationProgress);
                    interpLeftHandPos  = Vector3.Lerp(lastLeftHandPos, targetLeftHandPos, interpolationProgress);
                    interpRightHandPos = Vector3.Lerp(lastRightHandPos, targetRightHandPos, interpolationProgress);

                    interpHeadRot      = Quaternion.Lerp(lastHeadRot, targetHeadRot, interpolationProgress);
                    interpLeftHandRot  = Quaternion.Lerp(lastLeftHandRot, targetLeftHandRot, interpolationProgress);
                    interpRightHandRot = Quaternion.Lerp(lastRightHandRot, targetRightHandRot, interpolationProgress);

                    transform.position = interpHeadPos;
                }
            }
            catch (Exception e)
            {
                Logger.Error("Unable to lerp avatar position! Exception: " + e);
            }

            try
            {
                if (IllusionInjector.PluginManager.Plugins.Any(x => x.Name == "CameraPlus") && _camera == null)
                {
                    _camera = FindObjectsOfType <Camera>().FirstOrDefault(x => x.name == "Camera Plus");
                }
                if (playerNameText)
                {
                    playerNameText.rectTransform.rotation = Quaternion.LookRotation(playerNameText.rectTransform.position - WorldController.GetXRNodeWorldPosRot(XRNode.Head).Position);
                }
            }
            catch (Exception e)
            {
                Logger.Warning("Unable to rotate text to the camera! Exception: " + e);
            }
        }
Пример #15
0
 public void ActiveSceneChanged(Scene from, Scene to)
 {
     try
     {
         if (!SteamAPI.isLobbyConnected())
         {
             return;
         }
         if (to.name == "GameCore" || to.name == "MenuCore")
         {
             try
             {
                 PlayerController.Instance.DestroyAvatars();
                 if (to.name == "GameCore" && SongListUtils.InSong)
                 {
                     Logger.Debug("update scoreboard");
                     SteamAPI.StartGame();
                     InvokeRepeating("UpdateSongOffset", 0f, 1f);
                     Scoreboard.Instance.disabled = false;
                     List <PlayerPacket> connectedPlayers = Controllers.PlayerController.Instance.GetConnectedPlayerPackets();
                     for (int i = 0; i < connectedPlayers.Count; i++)
                     {
                         Scoreboard.Instance.UpsertScoreboardEntry(connectedPlayers[i].playerId, connectedPlayers[i].playerName, 0, 0);
                     }
                 }
                 else if (to.name == "MenuCore")
                 {
                     Scoreboard.Instance.RemoveAll();
                     Scoreboard.Instance.disabled = true;
                     if (from.name == "GameCore" && SongListUtils.InSong)
                     {
                         StartCoroutine(RunLobbyCleanup());
                     }
                 }
             } catch (Exception e)
             {
                 Logger.Debug($"Exception: {e}");
                 Logger.Error(e);
             }
         }
     }
     catch (Exception e)
     {
         Logger.Error($"(OnlineController) Exception on {_currentScene} scene activation! Exception: {e}");
     }
 }
Пример #16
0
        private static void refreshFriendsList(ListViewController leftViewController)
        {
            friends = SteamAPI.GetOnlineFriends();
            leftViewController.Data.Clear();
            CGameID gameId = SteamAPI.GetGameID();

            foreach (KeyValuePair <CSteamID, string[]> entry in friends)
            {
                if ("" + gameId != entry.Value[1] || entry.Value[1] == "0")
                {
                    continue;
                }
                Logger.Debug($"{entry.Value[0]} playing Beat Saber");
                leftViewController.Data.Add(new CustomCellInfo(entry.Value[0], "Playing Beat Saber"));
            }
            foreach (KeyValuePair <CSteamID, string[]> entry in friends)
            {
                if ("" + gameId == entry.Value[1] || entry.Value[1] == "0")
                {
                    continue;
                }
                Logger.Debug($"{entry.Value[0]} playing Other Game");
                leftViewController.Data.Add(new CustomCellInfo(entry.Value[0], "Playing Other Game"));
            }
            foreach (KeyValuePair <CSteamID, string[]> entry in friends)
            {
                if ("0" != entry.Value[1])
                {
                    continue;
                }
                Logger.Debug($"{entry.Value[0]} online");
                leftViewController.Data.Add(new CustomCellInfo(entry.Value[0], "Online"));
            }

            leftViewController._customListTableView.ReloadData();
            leftViewController._customListTableView.ScrollToCellWithIdx(0, TableView.ScrollPositionType.Beginning, false);
            leftViewController.DidSelectRowEvent = (view, row) =>
            {
                invite.interactable = false;
                CustomCellInfo cell = leftViewController.Data[row];
                KeyValuePair <CSteamID, string[]> friend = friends.Where(entry => entry.Value[0] == cell.text).First();
                selectedPlayer      = friend.Key.m_SteamID;
                invite.interactable = true;
            };
        }
 private void didSelectPlay()
 {
     try
     {
         var practice = ReflectionUtil.GetPrivateField <Button>(detail, "_practiceButton");
         Logger.Debug("Custom play button selected");
         if (!_partyFlowCoordinator || !_partyFlowCoordinator.isActivated)
         {
             toggleButtons(true);
             return;
         }
         toggleButtons(false);
         SteamAPI.RequestPlay(new GameplayModifiers(_gameplaySetupViewController.gameplayModifiers));
     } catch (Exception e)
     {
         Logger.Error(e);
     }
 }
Пример #18
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}");
            }
        }
Пример #19
0
        public void Awake()
        {
            if (instance != this)
            {
                instance = this;

                instance.StartCoroutine(Utils.AutoUpdater.GetLatestVersionDownload());
                DontDestroyOnLoad(this);
                SteamAPI.Init();
                Logger.Debug("CreateUI");
                try
                {
                    CreateUI();
                } catch (Exception e)
                {
                    Logger.Error($"Unable to create UI! Exception: {e}");
                }
            }
        }
Пример #20
0
 public void DestroyAvatars()
 {
     try
     {
         foreach (KeyValuePair <ulong, AvatarController> players in _connectedPlayerAvatars)
         {
             if (players.Value != null)
             {
                 Destroy(players.Value.gameObject);
             }
         }
         _connectedPlayers.Clear();
         _connectedPlayerAvatars.Clear();
     }
     catch (Exception e)
     {
         Logger.Error($"Unable to destroy avatars! Exception: {e}");
     }
 }
Пример #21
0
        public bool AllPlayersInMenu()
        {
            bool InMenu = !_playerInfo.InSong;

            if (!InMenu)
            {
                Logger.Debug("You are in a song");
            }
            for (int i = 0; i < _connectedPlayers.Count; i++)
            {
                if (InMenu && _connectedPlayers.Values.ToArray()[i].InSong)
                {
                    Logger.Debug(_connectedPlayers.Values.ToArray()[i].playerName + " is in song");
                    InMenu = false;
                    break;
                }
            }
            return(InMenu);
        }
Пример #22
0
 private void CreateMainMenuButton()
 {
     MultiplayerButton = MenuButtonUI.AddButton($"Multiplayer", "", delegate()
     {
         try
         {
             if (SteamAPI.isLobbyConnected())
             {
                 MultiplayerLobby.Instance.Present();
             }
             else
             {
                 MultiplayerListing.Instance.Present();
             }
         }
         catch (Exception e)
         {
             Logger.Error($"Unable to present flow coordinator! Exception: {e}");
         }
     });
 }
Пример #23
0
        IEnumerator RunLobbyCleanup()
        {
            yield return(new WaitUntil(delegate() { return true; }));

            Logger.Debug("Finished song, doing cleanup");
            try
            {
                WaitingMenu.Instance.Dismiss();
            } catch (Exception e)
            {
                Logger.Error($"Error dismissing WaitingMenu {e}");
            }
            WaitingMenu.firstInit  = true;
            WaitingMenu.queuedSong = null;
            WaitingMenu.autoReady  = false;
            SongListUtils.InSong   = false;
            Controllers.PlayerController.Instance._playerInfo.InSong = false;
            SteamAPI.SetSongOffset(0f);
            CancelInvoke("UpdateSongOffset");
            SteamAPI.FinishSong();
        }
Пример #24
0
 public static void refreshLobbyList()
 {
     availableLobbies.Clear();
     middleViewController.Data.Clear();
     try
     {
         Dictionary <ulong, LobbyInfo> lobbies = SteamAPI.LobbyData;
         foreach (KeyValuePair <ulong, LobbyInfo> entry in lobbies)
         {
             LobbyInfo info = SteamAPI.LobbyData[entry.Key];
             availableLobbies.Add(entry.Key, info.Joinable);
             middleViewController.Data.Add(new CustomCellInfo($"{(info.Joinable && info.TotalSlots - info.UsedSlots > 0 ? "":"[LOCKED]")}[{info.UsedSlots}/{info.TotalSlots}] {info.HostName}'s Lobby", $"{info.Status}"));
         }
     }
     catch (Exception e)
     {
         Logger.Error(e);
     }
     middleViewController._customListTableView.ReloadData();
     middleViewController._customListTableView.ScrollToRow(0, false);
     middleViewController.DidSelectRowEvent = (TableView view, int row) =>
     {
         ulong     clickedID = availableLobbies.Keys.ToArray()[row];
         LobbyInfo info      = SteamAPI.LobbyData[clickedID];
         if (clickedID != 0 && availableLobbies.Values.ToArray()[row] && info.TotalSlots - info.UsedSlots > 0)
         {
             Scoreboard.Instance.UpsertScoreboardEntry(Controllers.PlayerController.Instance._playerInfo.playerId, Controllers.PlayerController.Instance._playerInfo.playerName);
             Instance.Dismiss();
             MultiplayerLobby.Instance.Present();
             SteamAPI.JoinLobby(new CSteamID(clickedID));
         }
     };
     if (refresh)
     {
         refresh.interactable = true;
     }
 }
Пример #25
0
        public static void Init()
        {
            if (Instance == null)
            {
                try
                {
                    Instance = BeatSaberUI.CreateCustomMenu <CustomMenu>("Multiplayer Lobby");

                    CustomViewController middleViewController = BeatSaberUI.CreateViewController <CustomViewController>();
                    ListViewController   leftViewController   = BeatSaberUI.CreateViewController <ListViewController>();
                    rightViewController = BeatSaberUI.CreateViewController <TableViewController>();

                    Instance.SetMainViewController(middleViewController, true, (firstActivation, type) =>
                    {
                        if (firstActivation)
                        {
                            try
                            {
                                Button host = middleViewController.CreateUIButton("CreditsButton", new Vector2(BASE.x, BASE.y + 2.5f), new Vector2(25f, 7f));
                                host.SetButtonTextSize(3f);
                                host.ToggleWordWrapping(false);
                                host.SetButtonText("Disconnect");
                                host.onClick.AddListener(delegate
                                {
                                    try
                                    {
                                        SteamAPI.Disconnect();
                                        Instance.Dismiss();
                                        MultiplayerListing.Instance.Present();
                                    }
                                    catch (Exception e)
                                    {
                                        Logger.Error(e);
                                    }
                                });
                                float offs = 0;
                                offs      += 10f;
                                Button vc  = middleViewController.CreateUIButton("CreditsButton", new Vector2(BASE.x, BASE.y + 2.5f - offs), new Vector2(25f, 7f));
                                vc.SetButtonTextSize(3f);
                                vc.ToggleWordWrapping(false);
                                vc.SetButtonText(Controllers.PlayerController.Instance.VoipEnabled ? "Disable Voice Chat" : "Enable Voice Chat");
                                vc.onClick.AddListener(delegate
                                {
                                    try
                                    {
                                        if (!Controllers.PlayerController.Instance.VoipEnabled)
                                        {
                                            vc.SetButtonText("Disable Voice Chat");
                                            Controllers.PlayerController.Instance.VoipEnabled = true;
                                            SteamUser.StartVoiceRecording();
                                        }
                                        else
                                        {
                                            vc.SetButtonText("Enable Voice Chat");
                                            Controllers.PlayerController.Instance.VoipEnabled = false;
                                            SteamUser.StopVoiceRecording();
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Logger.Error(e);
                                    }
                                });
                                var t        = middleViewController.CreateText("You can use Online Lobby in the Main Menu to choose songs for your lobby. \n\nYou can also control all the default Game Modifiers for the lobby through the Online Lobby Menu as well.", new Vector2(0, BASE.y - 10f));
                                var tt       = middleViewController.CreateText("If something goes wrong, click the disconnect button above and just reconnect to the lobby.", new Vector2(0, 0 - BASE.y));
                                t.alignment  = TMPro.TextAlignmentOptions.Center;
                                tt.alignment = TMPro.TextAlignmentOptions.Center;
                            } catch (Exception e)
                            {
                                Data.Logger.Error(e);
                            }

                            /*   Button g = middleViewController.CreateUIButton("CreditsButton", new Vector2(0, 0), new Vector2(25f, 25f));
                             * g.SetButtonTextSize(7f);
                             * g.ToggleWordWrapping(false);
                             * g.SetButtonText("Select a Song");
                             * g.onClick.AddListener(delegate {
                             *     try
                             *     {
                             *         if (SteamAPI.IsHost())
                             *         {
                             *             SteamAPI.SetSong("112D7FA45FA06F36FF41029099E95B98", "TaKillYa");
                             *             SteamAPI.SetDifficulty((byte)2);
                             *             SteamAPI.RequestPlay(new GameplayModifiers(new GameplayModifiers()));
                             *         }
                             *     }
                             *     catch (Exception e)
                             *     {
                             *         Logger.Error(e);
                             *     }
                             * });*/
                        }
                    });
                    Instance.SetLeftViewController(leftViewController, false, (firstActivation, type) =>
                    {
                        if (firstActivation)
                        {
                            refreshFriendsList(leftViewController);
                            leftViewController.CreateText("Invite Friends", new Vector2(BASE.x + 62.5f, BASE.y));

                            Button b = leftViewController.CreateUIButton("CreditsButton", new Vector2(BASE.x + 80f, BASE.y + 2.5f), new Vector2(25f, 7f));
                            b.SetButtonText("Refresh");
                            b.SetButtonTextSize(3f);
                            b.ToggleWordWrapping(false);
                            b.onClick.AddListener(delegate()
                            {
                                refreshFriendsList(leftViewController);
                            });


                            invite = leftViewController.CreateUIButton("CreditsButton", new Vector2(BASE.x + 80f, 0 - BASE.y + 2.5f), new Vector2(25f, 7f));
                            invite.SetButtonText("Invite");
                            invite.SetButtonTextSize(3f);
                            invite.ToggleWordWrapping(false);
                            invite.interactable = false;
                            invite.onClick.AddListener(delegate()
                            {
                                if (selectedPlayer > 0)
                                {
                                    SteamAPI.InviteUserToLobby(new CSteamID(selectedPlayer));
                                }
                            });
                        }
                    });
                    Instance.SetRightViewController(rightViewController, false, (active, type) => {
                        if (active)
                        {
                            rightViewController.CreateText("Lobby Leaderboard", new Vector2(BASE.x + 62.5f, BASE.y));
                        }
                        RefreshScores();
                    });
                } catch (Exception e)
                {
                    Data.Logger.Error(e);
                }
            }
        }
Пример #26
0
 public static void LevelError(string error)
 {
     Logger.Error($"Error downloading song: {error}");
     downloading = false;
     RefreshData(null);
 }
Пример #27
0
        public void SetPlayerPacket(PlayerPacket _playerInfo, Vector3 offsetVector, bool isLocal)
        {
            if (_playerInfo == null)
            {
                playerNameText.gameObject.SetActive(false);
                if (rendererEnabled)
                {
                    SetRendererInChilds(avatar.GameObject.transform, false);
                    rendererEnabled = false;
                }
                return;
            }

            try
            {
                playerInfo = _playerInfo;

                if (!playerNameText)
                {
                    return;
                }
                if (avatar == null || ModelSaberAPI.cachedAvatars.First(x => x.Value == avatar.CustomAvatar).Key != playerInfo.avatarHash)
                {
                    if (ModelSaberAPI.cachedAvatars.ContainsKey(playerInfo.avatarHash))
                    {
                        if (ModelSaberAPI.cachedAvatars[playerInfo.avatarHash].IsLoaded)
                        {
                            if (avatar != null)
                            {
                                Destroy(avatar.GameObject);
                            }

                            avatar = AvatarSpawner.SpawnAvatar(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash], this);
                        }
                        else if (!pendingAvatars.Contains(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]))
                        {
                            pendingAvatars.Add(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]);
                            ModelSaberAPI.cachedAvatars[playerInfo.avatarHash].Load((CustomAvatar.CustomAvatar loadedAvatar, AvatarLoadResult result) =>
                            {
                                if (result == AvatarLoadResult.Completed)
                                {
                                    pendingAvatars.Remove(ModelSaberAPI.cachedAvatars[playerInfo.avatarHash]);
                                    AvatarLoaded?.Invoke(ModelSaberAPI.cachedAvatars.First(x => x.Value == avatar.CustomAvatar).Key, loadedAvatar);
                                }
                            });
                            AvatarLoaded += AvatarController_AvatarLoaded;
                        }
                        else
                        {
                            AvatarLoaded -= AvatarController_AvatarLoaded;
                            AvatarLoaded += AvatarController_AvatarLoaded;
                        }
                    }
                    else
                    {
                        if (ModelSaberAPI.queuedAvatars.Contains(playerInfo.avatarHash))
                        {
                            ModelSaberAPI.avatarDownloaded += AvatarDownloaded;
                        }
                        else
                        {
                            SharedCoroutineStarter.instance.StartCoroutine(ModelSaberAPI.DownloadAvatarCoroutine(playerInfo.avatarHash, (CustomAvatar.CustomAvatar avatar) => { AvatarDownloaded(playerInfo.avatarHash, avatar); }));
                        }
                    }
                }

                if (isLocal)
                {
                    playerNameText.gameObject.SetActive(false);
#if !DEBUG
                    if (rendererEnabled)
                    {
                        SetRendererInChilds(avatar.GameObject.transform, false);
                        rendererEnabled = false;
                    }
#endif
                }
                else
                {
                    playerNameText.gameObject.SetActive(true);
                    if (!rendererEnabled)
                    {
                        SetRendererInChilds(avatar.GameObject.transform, true);
                        rendererEnabled = true;
                    }
                }
                interpolationProgress = 0f;


                lastHeadPos   = targetHeadPos;
                targetHeadPos = _playerInfo.headPos + offsetVector;

                lastRightHandPos   = targetRightHandPos;
                targetRightHandPos = _playerInfo.rightHandPos + offsetVector;

                lastLeftHandPos   = targetLeftHandPos;
                targetLeftHandPos = _playerInfo.leftHandPos + offsetVector;

                lastHeadRot   = targetHeadRot;
                targetHeadRot = _playerInfo.headRot;

                lastRightHandRot   = targetRightHandRot;
                targetRightHandRot = _playerInfo.rightHandRot;

                lastLeftHandRot   = targetLeftHandRot;
                targetLeftHandRot = _playerInfo.leftHandRot;

                playerNameText.text = playerInfo.playerName;

                if (forcePlayerPacket)
                {
                    interpHeadPos      = targetHeadPos;
                    interpLeftHandPos  = targetLeftHandPos;
                    interpRightHandPos = targetRightHandPos;

                    interpHeadRot      = targetHeadRot;
                    interpLeftHandRot  = targetLeftHandRot;
                    interpRightHandRot = targetRightHandRot;

                    transform.position = interpHeadPos;
                }
            }
            catch (Exception e)
            {
                Logger.Error($"Avatar controller exception: {_playerInfo.playerName}: {e}");
            }
        }
Пример #28
0
        public static void Init()
        {
            if (Instance == null)
            {
                try
                {
                    Instance = BeatSaberUI.CreateCustomMenu <CustomMenu>("Multiplayer Lobby");

                    CustomViewController middleViewController = BeatSaberUI.CreateViewController <CustomViewController>();
                    ListViewController   leftViewController   = BeatSaberUI.CreateViewController <ListViewController>();
                    rightViewController = BeatSaberUI.CreateViewController <TableViewController>();

                    Instance.SetMainViewController(middleViewController, true, (firstActivation, type) =>
                    {
                        if (firstActivation)
                        {
                            try
                            {
                                Button host = middleViewController.CreateUIButton("CreditsButton", new Vector2(BASE.x, BASE.y + 2.5f), new Vector2(25f, 7f));
                                host.SetButtonTextSize(3f);
                                host.ToggleWordWrapping(false);
                                host.SetButtonText("Disconnect");
                                host.onClick.AddListener(delegate
                                {
                                    try
                                    {
                                        SteamAPI.Disconnect();
                                        Instance.Dismiss();
                                        MultiplayerListing.Instance.Present();
                                    }
                                    catch (Exception e)
                                    {
                                        Logger.Error(e);
                                    }
                                });
                                float offs = 0;
                                offs      += 10f;
                                Button vc  = middleViewController.CreateUIButton("CreditsButton", new Vector2(BASE.x, BASE.y + 2.5f - offs), new Vector2(25f, 7f));
                                vc.SetButtonTextSize(3f);
                                vc.ToggleWordWrapping(false);
                                vc.SetButtonText(VoiceChatWorker.VoipEnabled ? "Disable Voice Chat" : "Enable Voice Chat");
                                vc.onClick.AddListener(delegate
                                {
                                    try
                                    {
                                        if (!VoiceChatWorker.VoipEnabled)
                                        {
                                            vc.SetButtonText("Disable Voice Chat");
                                            VoiceChatWorker.VoipEnabled = true;
                                            SteamUser.StartVoiceRecording();
                                        }
                                        else
                                        {
                                            vc.SetButtonText("Enable Voice Chat");
                                            VoiceChatWorker.VoipEnabled = false;
                                            SteamUser.StopVoiceRecording();
                                        }
                                    }
                                    catch (Exception e)
                                    {
                                        Logger.Error(e);
                                    }
                                });
                                offs  += 10f;
                                rejoin = middleViewController.CreateUIButton("CreditsButton", new Vector2(BASE.x, BASE.y + 2.5f - offs), new Vector2(25f, 7f));
                                rejoin.SetButtonTextSize(3f);
                                rejoin.ToggleWordWrapping(false);
                                rejoin.SetButtonText("Re-Join Song");
                                rejoin.interactable = false;
                                rejoin.onClick.AddListener(delegate
                                {
                                    if (SteamAPI.GetLobbyData().Screen == LobbyPacket.SCREEN_TYPE.IN_GAME && SteamAPI.GetLobbyData().CurrentSongOffset > 0f)
                                    {
                                        WaitingMenu.autoReady             = true;
                                        WaitingMenu.timeRequestedToLaunch = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
                                        WaitingMenu.Instance.Present();
                                    }
                                });
                                bodyText           = middleViewController.CreateText("You can use Online Lobby in the Main Menu to choose songs for your lobby. \n\nYou can also control all the default Game Modifiers for the lobby through the Online Lobby Menu as well.", new Vector2(0, BASE.y - 10f));
                                var tt             = middleViewController.CreateText("If something goes wrong, click the disconnect button above and just reconnect to the lobby.", new Vector2(0, 0 - BASE.y));
                                bodyText.alignment = TMPro.TextAlignmentOptions.Center;
                                tt.alignment       = TMPro.TextAlignmentOptions.Center;
                            } catch (Exception e)
                            {
                                Logger.Error(e);
                            }
                        }
                    });
                    Instance.SetLeftViewController(leftViewController, false, (firstActivation, type) =>
                    {
                        if (firstActivation)
                        {
                            refreshFriendsList(leftViewController);
                            leftViewController.CreateText("Invite Friends", new Vector2(BASE.x + 62.5f, BASE.y));

                            Button b = leftViewController.CreateUIButton("CreditsButton", new Vector2(BASE.x + 80f, BASE.y + 2.5f), new Vector2(25f, 7f));
                            b.SetButtonText("Refresh");
                            b.SetButtonTextSize(3f);
                            b.ToggleWordWrapping(false);
                            b.onClick.AddListener(delegate()
                            {
                                refreshFriendsList(leftViewController);
                            });


                            invite = leftViewController.CreateUIButton("CreditsButton", new Vector2(BASE.x + 80f, 0 - BASE.y + 2.5f), new Vector2(25f, 7f));
                            invite.SetButtonText("Invite");
                            invite.SetButtonTextSize(3f);
                            invite.ToggleWordWrapping(false);
                            invite.interactable = false;
                            invite.onClick.AddListener(delegate()
                            {
                                if (selectedPlayer > 0)
                                {
                                    SteamAPI.InviteUserToLobby(new CSteamID(selectedPlayer));
                                }
                            });
                        }
                    });
                    Instance.SetRightViewController(rightViewController, false, (firstActivation, type) => {
                        if (firstActivation)
                        {
                            rightViewController.CreateText("Lobby Leaderboard", new Vector2(BASE.x + 62.5f, BASE.y));
                        }
                        RefreshScores();
                    });
                } catch (Exception e)
                {
                    Logger.Error(e);
                }
            }
        }
Пример #29
0
        public void UpsertPlayer(PlayerPacket info)
        {
            if (info.playerId == _playerInfo.playerId)
            {
                return;
            }
            try
            {
                if (!_connectedPlayers.Keys.Contains(info.playerId))
                {
                    _connectedPlayers.Add(info.playerId, info);
                    if ((Config.Instance.AvatarsInLobby && Plugin.instance.CurrentScene == "MenuCore") || (Config.Instance.AvatarsInGame && Plugin.instance.CurrentScene == "GameCore"))
                    {
                        AvatarController avatar = new GameObject("AvatarController").AddComponent <AvatarController>();
                        avatar.SetPlayerPacket(info, new Vector3(0, 0, 0), info.playerId == _playerInfo.playerId);
                        _connectedPlayerAvatars.Add(info.playerId, avatar);
                    }
                    MultiplayerLobby.RefreshScores();
                    Scoreboard.Instance.UpsertScoreboardEntry(info.playerId, info.playerName);
                    return;
                }

                if (_connectedPlayers.ContainsKey(info.playerId))
                {
                    if (info.playerScore != _connectedPlayers[info.playerId].playerScore || info.playerComboBlocks != _connectedPlayers[info.playerId].playerComboBlocks)
                    {
                        Scoreboard.Instance.UpsertScoreboardEntry(info.playerId, info.playerName, (int)info.playerScore, (int)info.playerComboBlocks);
                        MultiplayerLobby.RefreshScores();
                    }
                    if (_connectedPlayerAvatars.ContainsKey(info.playerId) && (Config.Instance.AvatarsInLobby && Plugin.instance.CurrentScene == "MenuCore") || (Config.Instance.AvatarsInGame && Plugin.instance.CurrentScene == "GameCore"))
                    {
                        Vector3 offset = new Vector3(0, 0, 0);
                        if (Plugin.instance.CurrentScene == "GameCore")
                        {
                            ulong[] playerInfosByID = new ulong[_connectedPlayers.Count + 1];
                            playerInfosByID[0] = _playerInfo.playerId;
                            _connectedPlayers.Keys.ToList().CopyTo(playerInfosByID, 1);
                            Array.Sort(playerInfosByID);
                            offset = new Vector3((Array.IndexOf(playerInfosByID, info.playerId) - Array.IndexOf(playerInfosByID, _playerInfo.playerId)) * 2f, 0, Math.Abs((Array.IndexOf(playerInfosByID, info.playerId) - Array.IndexOf(playerInfosByID, _playerInfo.playerId)) * 2.5f));
                        }

                        _connectedPlayerAvatars[info.playerId].SetPlayerPacket(info, offset, info.playerId == _playerInfo.playerId);
                    }
                    bool changedReady = (_connectedPlayers[info.playerId].Ready != info.Ready || _connectedPlayers[info.playerId].playerProgress != info.playerProgress);
                    _connectedPlayers[info.playerId] = info;
                    MockPartyViewController.Instance.UpdatePlayButton();
                    if (changedReady)
                    {
                        WaitingMenu.RefreshData();
                        if (SteamAPI.IsHost())
                        {
                            if (info.Ready)
                            {
                                if (_connectedPlayers.Values.ToList().All(u => u.Ready))
                                {
                                    Data.Logger.Debug($"Everyone has confirmed that they are ready to play, broadcast that we want them all to start playing");
                                    SteamAPI.StartPlaying();
                                }
                            }
                            else
                            {
                                if (_connectedPlayers.Values.ToList().All(u => !u.Ready))
                                {
                                    Data.Logger.Debug($"Everyone has confirmed they are in game, set the lobby screen to in game");
                                    SteamAPI.StartGame();
                                }
                            }
                        }
                    }
                }
            } catch (Exception e)
            {
                Logger.Error(e);
            }
        }