Exemplo 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}");
            }
        }
Exemplo n.º 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(" ", "");
                        PlayerInfo info    = new PlayerInfo(message);
                        if (info.voip != null && info.voip.Length > 0)
                        {
                            if (VoipEnabled)
                            {
                                PlayVoip(info.voip);
                            }
                            info.voip = new byte[0];
                        }
                        if (info.playerId != SteamAPI.GetUserID() && SteamAPI.getLobbyID().m_SteamID != 0)
                        {
                            UpsertPlayer(info);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Data.Logger.Error(e);
            }
        }
Exemplo n.º 3
0
        public static void Init()
        {
            if (Instance == null)
            {
                Instance = BeatSaberUI.CreateCustomMenu <CustomMenu>("Online Multiplayer");

                middleViewController = BeatSaberUI.CreateViewController <ListViewController>();


                Instance.SetMainViewController(middleViewController, true, (firstActivation, type) =>
                {
                    refreshAvailableLobbies();
                    if (firstActivation)
                    {
                        middleViewController.CreateText("Available Lobbies", new Vector2(BASE.x + 60f, BASE.y));

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

                        if (!SteamAPI.isLobbyConnected())
                        {
                            Button host = middleViewController.CreateUIButton("CreditsButton", new Vector2(BASE.x, BASE.y + 2.5f), new Vector2(25f, 7f));
                            host.SetButtonTextSize(3f);
                            host.ToggleWordWrapping(false);

                            host.onClick.RemoveAllListeners();
                            host.SetButtonText("Host Public Lobby");
                            host.onClick.AddListener(delegate()
                            {
                                SteamAPI.CreateLobby(false);
                                Instance.Dismiss();
                                MultiplayerLobby.Instance.Present();
                            });

                            Button hostP = middleViewController.CreateUIButton("CreditsButton", new Vector2(BASE.x, BASE.y + 2.5f - 10f), new Vector2(25f, 7f));
                            hostP.SetButtonTextSize(3f);
                            hostP.ToggleWordWrapping(false);

                            hostP.onClick.RemoveAllListeners();
                            hostP.SetButtonText("Host Private Lobby");
                            hostP.onClick.AddListener(delegate()
                            {
                                SteamAPI.CreateLobby(true);
                                Instance.Dismiss();
                                MultiplayerLobby.Instance.Present();
                            });
                        }
                    }
                });
            }
        }
Exemplo n.º 4
0
        private static void refreshAvailableLobbies()
        {
            lobbies = new Dictionary <CSteamID, LobbyPacket>();

            if (refresh)
            {
                refresh.interactable = true;
            }
            SteamAPI.RequestLobbies();
        }
Exemplo n.º 5
0
        public void Awake()
        {
            if (Instance != this)
            {
                Instance = this;
                DontDestroyOnLoad(gameObject);

                _playerInfo   = new PlayerInfo(SteamAPI.GetUserName(), SteamAPI.GetUserID());
                _currentScene = SceneManager.GetActiveScene().name;
            }
        }
Exemplo n.º 6
0
        public void Awake()
        {
            if (instance != this)
            {
                instance = this;

                instance.StartCoroutine(Utils.AutoUpdater.GetLatestVersionDownload());
                DontDestroyOnLoad(this);
                SteamAPI.Init();
                CreateUI();
            }
        }
Exemplo n.º 7
0
        public static void SendToAllInLobby(byte[] bytes)
        {
            int numMembers = SteamMatchmaking.GetNumLobbyMembers(_lobbyInfo.LobbyID);

            for (int i = 0; i < numMembers; i++)
            {
                CSteamID member = SteamMatchmaking.GetLobbyMemberByIndex(_lobbyInfo.LobbyID, i);
                if (member.m_SteamID != SteamAPI.GetUserID())
                {
                    SteamNetworking.SendP2PPacket(member, bytes, (uint)bytes.Length, EP2PSend.k_EP2PSendReliable);
                }
            }
        }
Exemplo n.º 8
0
        private void CreateSettingsMenu()
        {
            var settingsMenu = SettingsUI.CreateSubMenu(Plugin.instance.Name);

            var AutoStartLobby = settingsMenu.AddBool("Auto-Start Lobby", "Opens up a lobby when you launch the game");

            AutoStartLobby.GetValue += delegate { return(Config.Instance.AutoStartLobby); };
            AutoStartLobby.SetValue += delegate(bool value) { Config.Instance.AutoStartLobby = value; };

            var IsPublic = settingsMenu.AddBool("Auto-Start Privacy", "Configures the privacy of lobbies that are auto-started");

            IsPublic.DisabledText = "Friends Only";
            IsPublic.EnabledText  = "Public";
            IsPublic.GetValue    += delegate { return(Config.Instance.IsPublic); };
            IsPublic.SetValue    += delegate(bool value) { Config.Instance.IsPublic = value; };

            var MaxLobbySite = settingsMenu.AddInt("Lobby Size", "Configure the amount of users you want to be able to join your lobby.", 2, 15, 1);

            MaxLobbySite.GetValue += delegate { return(Config.Instance.MaxLobbySize); };
            MaxLobbySite.SetValue += delegate(int value) {
                SteamMatchmaking.SetLobbyMemberLimit(SteamAPI.getLobbyID(), value);
                Config.Instance.MaxLobbySize = value;
            };

            var AvatarsInLobby = settingsMenu.AddBool("Enable Avatars In Lobby", "Turns avatars on for you in the waiting lobby");

            AvatarsInLobby.GetValue += delegate { return(Config.Instance.AvatarsInLobby); };
            AvatarsInLobby.SetValue += delegate(bool value) { Config.Instance.AvatarsInLobby = value; };

            var AvatarsInGame = settingsMenu.AddBool("Enable Avatars In Game", "Turns avatars on for you while playing songs");

            AvatarsInGame.GetValue += delegate { return(Config.Instance.AvatarsInGame); };
            AvatarsInGame.SetValue += delegate(bool value) { Config.Instance.AvatarsInGame = value; };

            var NetworkQuality = settingsMenu.AddInt("Network Quality", "Higher number, smoother avatar. Note that this effects how you appear to others. ", 0, 5, 1);

            NetworkQuality.GetValue += delegate { return(Config.Instance.NetworkQuality); };
            NetworkQuality.SetValue += delegate(int value) {
                Config.Instance.NetworkQuality = value;
                if (Controllers.PlayerController.Instance.isBroadcasting)
                {
                    Controllers.PlayerController.Instance.StopBroadcasting();
                    Controllers.PlayerController.Instance.StartBroadcasting();
                }
            };

            var NetworkScaling = settingsMenu.AddBool("Network Scaling", "Scales your network traffic based on the size of your lobby.");

            NetworkScaling.GetValue += delegate { return(Config.Instance.NetworkScaling); };
            NetworkScaling.SetValue += delegate(bool value) { Config.Instance.NetworkScaling = value; };
        }
Exemplo n.º 9
0
 void BroadcastPlayerInfo()
 {
     try
     {
         UpdatePlayerInfo();
         SteamAPI.SendPlayerInfo(_playerInfo);
         if (_playerInfo.voip != null && _playerInfo.voip.Length > 0)
         {
             _playerInfo.voip = new byte[0];
         }
     } catch (Exception e)
     {
         Data.Logger.Error(e);
     }
 }
Exemplo n.º 10
0
        public static void OnLobbyEnter(LobbyEnter_t pCallback)
        {
            Logger.Debug($"You have entered lobby {pCallback.m_ulSteamIDLobby}");
            Controllers.PlayerController.Instance.StartBroadcasting();
            SteamAPI.SetConnectionState(SteamAPI.ConnectionState.CONNECTED);
            SteamAPI.SendPlayerPacket(Controllers.PlayerController.Instance._playerInfo);
            LobbyPacket info = new LobbyPacket(SteamMatchmaking.GetLobbyData(new CSteamID(pCallback.m_ulSteamIDLobby), "LOBBY_INFO"));

            SteamAPI.UpdateLobbyPacket(info);
            if (info.Screen == LobbyPacket.SCREEN_TYPE.IN_GAME && info.CurrentSongOffset > 0f)
            {
                WaitingMenu.autoReady             = true;
                WaitingMenu.timeRequestedToLaunch = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeSeconds();
                WaitingMenu.Instance.Present();
            }
        }
Exemplo n.º 11
0
        private static void refreshAvailableLobbies()
        {
            lobbies = new Dictionary <CSteamID, LobbyInfo>();

            if (refresh)
            {
                refresh.interactable = true;
            }
            if (!sorting)
            {
                SteamAPI.RequestLobbies();
            }
            else
            {
                SteamAPI.RequestAvailableLobbies();
            }
        }
Exemplo n.º 12
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;
            };
        }
Exemplo n.º 13
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}");
            }
        }
Exemplo n.º 14
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}");
                }
            }
        }
Exemplo n.º 15
0
        public void UpdatePlayerInfo()
        {
            _playerInfo.avatarHash = ModelSaberAPI.cachedAvatars.FirstOrDefault(x => x.Value == CustomAvatar.Plugin.Instance.PlayerAvatarManager.GetCurrentAvatar()).Key;
            if (_playerInfo.avatarHash == null)
            {
                _playerInfo.avatarHash = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
            }

            _playerInfo.playerName = SteamAPI.GetUserName();
            _playerInfo.playerId   = SteamAPI.GetUserID();

            WorldController.CharacterPosition pos = WorldController.GetCharacterInfo();
            _playerInfo.headPos      = pos.headPos;
            _playerInfo.headRot      = pos.headRot;
            _playerInfo.leftHandPos  = pos.leftHandPos;
            _playerInfo.leftHandRot  = pos.leftHandRot;
            _playerInfo.rightHandPos = pos.rightHandPos;
            _playerInfo.rightHandRot = pos.rightHandRot;
        }
Exemplo n.º 16
0
        public void OnP2PSessionRequest(P2PSessionRequest_t pCallback)
        {
            try
            {
                Logger.Debug($"{pCallback.m_steamIDRemote} requested a P2P session");

                int numMembers = SteamMatchmaking.GetNumLobbyMembers(SteamAPI.getLobbyID());
                for (int i = 0; i < numMembers; i++)
                {
                    var member = SteamMatchmaking.GetLobbyMemberByIndex(SteamAPI.getLobbyID(), i);
                    if (member.m_SteamID == pCallback.m_steamIDRemote.m_SteamID)
                    {
                        Logger.Debug($"{pCallback.m_steamIDRemote} is in our lobby, lets accept their P2P session");
                        bool ret = SteamNetworking.AcceptP2PSessionWithUser(pCallback.m_steamIDRemote);
                    }
                }
            } catch (Exception e)
            {
                Logger.Error(e);
            }
        }
Exemplo n.º 17
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}");
         }
     });
 }
Exemplo n.º 18
0
 public static void UpdateJoinButton()
 {
     //if (!Instance || !Instance.isActiveAndEnabled) { return; }
     if (!SteamAPI.IsHost() && SteamAPI.GetLobbyData().Screen == LobbyPacket.SCREEN_TYPE.MENU)
     {
         bodyText.text = "Waiting for host to select a song";
     }
     if (SteamAPI.GetLobbyData().Screen != LobbyPacket.SCREEN_TYPE.IN_GAME)
     {
         return;
     }
     bodyText.text = $"Currently playing {SteamAPI.GetSongName()} @ {Math.Floor(SteamAPI.GetSongOffset() / 60f)}:{Math.Floor(SteamAPI.GetSongOffset() % 60f)}";
     if (SteamAPI.GetLobbyData().CurrentSongOffset > 0f)
     {
         rejoin.interactable = true;
     }
     else
     {
         rejoin.interactable = false;
     }
 }
Exemplo n.º 19
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;
     }
 }
Exemplo n.º 20
0
        private void CreateSettingsMenu()
        {
            var settingsMenu = SettingsUI.CreateSubMenu(Plugin.instance.Name);

            var AutoStartLobby = settingsMenu.AddList("Auto-Start Lobby", new float[3] {
                0, 1, 2
            });

            AutoStartLobby.GetValue += delegate { return(_autoStart); };
            AutoStartLobby.SetValue += delegate(float value)
            {
                _autoStart = value;
                switch (value)
                {
                default:
                case 0:
                    Config.Instance.AutoStartLobby = false;
                    break;

                case 1:
                    Config.Instance.AutoStartLobby = true;
                    Config.Instance.IsPublic       = false;
                    break;

                case 2:
                    Config.Instance.AutoStartLobby = true;
                    Config.Instance.IsPublic       = true;
                    break;
                }
            };
            AutoStartLobby.FormatValue += delegate(float value)
            {
                switch (value)
                {
                default:
                case 0:
                    return("Disabled");

                case 1:
                    return("Private Lobby");

                case 2:
                    return("Public Lobby");
                }
            };


            var MaxLobbySite = settingsMenu.AddInt("Lobby Size", "Configure the amount of users you want to be able to join your lobby.", 2, 15, 1);

            MaxLobbySite.GetValue += delegate { return(Config.Instance.MaxLobbySize); };
            MaxLobbySite.SetValue += delegate(int value) {
                SteamMatchmaking.SetLobbyMemberLimit(SteamAPI.getLobbyID(), value);
                Config.Instance.MaxLobbySize = value;
            };

            var Volume = settingsMenu.AddInt("Voice Volume", "Higher numbers are louder", 1, 20, 1);

            Volume.GetValue += delegate { return((int)Config.Instance.Volume); };
            Volume.SetValue += delegate(int value) {
                Config.Instance.Volume = (float)value;
                AudioMixerGroup g = Utils.Assets.AudioGroup;
                g.audioMixer.SetFloat("MasterVolume", (float)value);
            };


            var Avatar = settingsMenu.AddList("Enable Avatars", new float[4] {
                0, 1, 2, 3
            });

            Avatar.GetValue += delegate { return(_avatarState); };
            Avatar.SetValue += delegate(float value) { _avatarState = value;
                                                       switch (value)
                                                       {
                                                       default:
                                                       case 0:
                                                           Config.Instance.AvatarsInLobby = false;
                                                           Config.Instance.AvatarsInGame  = false;
                                                           break;

                                                       case 1:
                                                           Config.Instance.AvatarsInLobby = true;
                                                           Config.Instance.AvatarsInGame  = false;
                                                           break;

                                                       case 2:
                                                           Config.Instance.AvatarsInLobby = false;
                                                           Config.Instance.AvatarsInGame  = true;
                                                           break;

                                                       case 3:
                                                           Config.Instance.AvatarsInLobby = true;
                                                           Config.Instance.AvatarsInGame  = true;
                                                           break;
                                                       }
            };
            Avatar.FormatValue += delegate(float value)
            {
                switch (value)
                {
                default:
                case 0:
                    return("Disabled");

                case 1:
                    return("Lobby Only");

                case 2:
                    return("InGame Only");

                case 3:
                    return("Enabled");
                }
            };

            var NetworkQuality = settingsMenu.AddInt("Network Quality", "Higher number, smoother avatar. Note that this effects how you appear to others. ", 0, 5, 1);

            NetworkQuality.GetValue += delegate { return(Config.Instance.NetworkQuality); };
            NetworkQuality.SetValue += delegate(int value) {
                Config.Instance.NetworkQuality = value;
                if (Controllers.PlayerController.Instance.isBroadcasting)
                {
                    Controllers.PlayerController.Instance.StopBroadcasting();
                    Controllers.PlayerController.Instance.StartBroadcasting();
                }
            };
        }
Exemplo n.º 21
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);
                }
            }
        }
Exemplo n.º 22
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();
                    }
                }
            }
        }
Exemplo n.º 23
0
 private void OnGameLobbyJoinRequested(GameLobbyJoinRequested_t pCallback)
 {
     Logger.Debug($"Attempting to join {pCallback.m_steamIDFriend}'s lobby @ {pCallback.m_steamIDLobby}");
     SteamAPI.JoinLobby(pCallback.m_steamIDLobby);
 }
Exemplo n.º 24
0
        public void UpsertPlayer(PlayerInfo 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 == "Menu") || (Config.Instance.AvatarsInGame && Plugin.instance.CurrentScene == "GameCore"))
                    {
                        AvatarController avatar = new GameObject("AvatarController").AddComponent <AvatarController>();
                        avatar.SetPlayerInfo(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 == "Menu") || (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].SetPlayerInfo(info, offset, info.playerId == _playerInfo.playerId);
                    }
                    bool changedDownloading = (_connectedPlayers[info.playerId].Downloading != info.Downloading || _connectedPlayers[info.playerId].playerProgress != info.playerProgress);

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