Skip to content

Commit c56738c

Browse files
committed
Add in network scaling mode and other enhancements
1 parent 70da717 commit c56738c

File tree

6 files changed

+56
-41
lines changed

6 files changed

+56
-41
lines changed

BeatSaberOnline/Controllers/GameController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace BeatSaberOnline.Controllers
1616
class GameController : MonoBehaviour
1717
{
1818
public static GameController Instance;
19+
public static float TPS_MODIFIER = 1;
1920
public static float TPS
2021
{
2122
get
@@ -42,6 +43,7 @@ public static float TPS
4243
tps = 30;
4344
break;
4445
}
46+
tps *= TPS_MODIFIER;
4547
return 1f / tps;
4648
}
4749
}

BeatSaberOnline/Controllers/PlayerController.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ public void StopBroadcasting()
6363
isBroadcasting = false;
6464
CancelInvoke("BroadcastPlayerInfo");
6565
}
66+
67+
public void RestartBroadcasting()
68+
{
69+
StopBroadcasting();
70+
StartBroadcasting();
71+
}
6672
public void DestroyAvatars()
6773
{
6874
try
@@ -163,7 +169,7 @@ public void UpsertPlayer(PlayerInfo info)
163169
playerInfosByID[0] = _playerInfo.playerId;
164170
_connectedPlayers.Keys.ToList().CopyTo(playerInfosByID, 1);
165171
Array.Sort(playerInfosByID);
166-
offset = new Vector3((Array.IndexOf(playerInfosByID, info.playerId) - Array.IndexOf(playerInfosByID, _playerInfo.playerId)) * 2.5f, 0, Math.Abs((Array.IndexOf(playerInfosByID, info.playerId) - Array.IndexOf(playerInfosByID, _playerInfo.playerId)) * 2f));
172+
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));
167173
}
168174

169175
_connectedPlayerAvatars[info.playerId].SetPlayerInfo(info, offset, info.playerId == _playerInfo.playerId);

BeatSaberOnline/Data/Steam/SteamAPI.cs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ public static int getUserCount()
236236
public static void FinishSong()
237237
{
238238
Logger.Debug($"We have finished the song");
239-
240239
setLobbyStatus("Waiting In Menu");
241-
242240
}
243241

244242
private static void SendLobbyInfo(bool reqHost = false)
@@ -247,18 +245,6 @@ private static void SendLobbyInfo(bool reqHost = false)
247245
Logger.Debug($"Sending {_lobbyInfo.ToString()}");
248246
SteamMatchmaking.SetLobbyData(_lobbyInfo.LobbyID, "LOBBY_INFO", _lobbyInfo.Serialize());
249247
}
250-
public static void IncreaseSlots()
251-
{
252-
_lobbyInfo.TotalSlots += 1;
253-
if (_lobbyInfo.TotalSlots > _lobbyInfo.MaxSlots)
254-
{
255-
_lobbyInfo.TotalSlots = 2;
256-
}
257-
Logger.Debug($"Increasing the lobby slots to {_lobbyInfo.TotalSlots}");
258-
259-
SendLobbyInfo(true);
260-
SteamMatchmaking.SetLobbyMemberLimit(_lobbyInfo.LobbyID, _lobbyInfo.TotalSlots);
261-
}
262248

263249
public static CGameID GetGameID()
264250
{
@@ -323,6 +309,17 @@ public static void OpenInviteScreen()
323309
public static void PlayerConnected()
324310
{
325311
_lobbyInfo.UsedSlots += 1;
312+
if (Config.Instance.NetworkScaling && _lobbyInfo.UsedSlots % 5 == 0)
313+
{
314+
float mod = _lobbyInfo.UsedSlots / 5;
315+
float modifier = mod - (mod * 0.88f);
316+
if (modifier > 0.6)
317+
{
318+
modifier = 0.6f;
319+
}
320+
GameController.TPS_MODIFIER = 1 - modifier;
321+
Controllers.PlayerController.Instance.RestartBroadcasting();
322+
}
326323
if (IsHost())
327324
{
328325
SendLobbyInfo(true);
@@ -331,6 +328,17 @@ public static void PlayerConnected()
331328
public static void PlayerDisconnected()
332329
{
333330
_lobbyInfo.UsedSlots -= 1;
331+
if (Config.Instance.NetworkScaling && _lobbyInfo.UsedSlots % 5 == 0)
332+
{
333+
float mod = _lobbyInfo.UsedSlots / 5;
334+
float modifier = mod - (mod * 0.88f);
335+
if (modifier > 0.6)
336+
{
337+
modifier = 0.6f;
338+
}
339+
GameController.TPS_MODIFIER = 1 - modifier;
340+
Controllers.PlayerController.Instance.RestartBroadcasting();
341+
}
334342
if (IsHost())
335343
{
336344
SendLobbyInfo(true);

BeatSaberOnline/Utils/Config.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ public class Config
1010
private bool _isPublic;
1111
private int _maxLobbySize;
1212
private bool _noFailMode;
13-
private bool _debugMode;
1413
private bool _avatarsInLobby;
1514
private bool _avatarsInGame;
1615
private int _networkQuality;
16+
private bool _networkScaling;
1717

1818
private static Config _instance;
1919

@@ -118,15 +118,6 @@ public bool NoFailMode
118118
MarkDirty();
119119
}
120120
}
121-
public bool DebugMode
122-
{
123-
get { return _debugMode; }
124-
set
125-
{
126-
_debugMode = value;
127-
MarkDirty();
128-
}
129-
}
130121
public bool AvatarsInLobby
131122
{
132123
get { return _avatarsInLobby; }
@@ -159,17 +150,27 @@ public int NetworkQuality
159150
MarkDirty();
160151
}
161152
}
162-
153+
154+
public bool NetworkScaling
155+
{
156+
get { return _networkScaling; }
157+
set
158+
{
159+
_networkScaling = value;
160+
MarkDirty();
161+
}
162+
}
163+
163164
Config()
164165
{
165166
_autoStartLobby = false;
166167
_isPublic = true;
167168
_maxLobbySize = 5;
168169
_noFailMode = true;
169-
_debugMode = false;
170170
_avatarsInLobby = true;
171171
_avatarsInGame = true;
172-
_networkQuality = 3;
172+
_networkQuality = 4;
173+
_networkScaling = false;
173174
IsDirty = true;
174175
}
175176

BeatSaberOnline/Utils/Logger.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static void Error(object message)
4040

4141
private static void Write(string type, object message)
4242
{
43-
if ((type == "Debug" && Config.Instance.DebugMode) || type != "Debug")
43+
if (type != "Debug")
4444
{
4545
Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} [{loggerName}] [{type}] ${message}");
4646
}

BeatSaberOnline/Views/PluginUI.cs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,33 +87,32 @@ private void CreateSettingsMenu()
8787
{
8888
var settingsMenu = SettingsUI.CreateSubMenu(Plugin.instance.Name);
8989

90-
var AutoStartLobby = settingsMenu.AddBool("Auto-Start Lobby");
90+
var AutoStartLobby = settingsMenu.AddBool("Auto-Start Lobby", "Opens up a lobby when you launch the game");
9191
AutoStartLobby.GetValue += delegate { return Config.Instance.AutoStartLobby; };
9292
AutoStartLobby.SetValue += delegate (bool value) { Config.Instance.AutoStartLobby = value; };
9393

94-
var IsPublic = settingsMenu.AddBool("Auto-Start Privacy");
94+
var IsPublic = settingsMenu.AddBool("Auto-Start Privacy", "Configures the privacy of lobbies that are auto-started");
9595
IsPublic.DisabledText = "Friends Only";
9696
IsPublic.EnabledText = "Public";
9797
IsPublic.GetValue += delegate { return Config.Instance.IsPublic; };
9898
IsPublic.SetValue += delegate (bool value) { Config.Instance.IsPublic = value; };
9999

100-
var MaxLobbySite = settingsMenu.AddInt("Lobby Size", 2, 10, 1);
100+
var MaxLobbySite = settingsMenu.AddInt("Lobby Size", "Configure the amount of users you want to be able to join your lobby.", 2, 15, 1);
101101
MaxLobbySite.GetValue += delegate { return Config.Instance.MaxLobbySize; };
102102
MaxLobbySite.SetValue += delegate (int value) {
103103
SteamMatchmaking.SetLobbyMemberLimit(SteamAPI.getLobbyID(), value);
104104
Config.Instance.MaxLobbySize = value;
105105
};
106106

107-
var AvatarsInLobby = settingsMenu.AddBool("Enable Avatars In Lobby");
107+
var AvatarsInLobby = settingsMenu.AddBool("Enable Avatars In Lobby", "Turns avatars on for you in the waiting lobby");
108108
AvatarsInLobby.GetValue += delegate { return Config.Instance.AvatarsInLobby; };
109109
AvatarsInLobby.SetValue += delegate (bool value) { Config.Instance.AvatarsInLobby = value; };
110110

111-
var AvatarsInGame = settingsMenu.AddBool("Enable Avatars In Game");
111+
var AvatarsInGame = settingsMenu.AddBool("Enable Avatars In Game", "Turns avatars on for you while playing songs");
112112
AvatarsInGame.GetValue += delegate { return Config.Instance.AvatarsInGame; };
113113
AvatarsInGame.SetValue += delegate (bool value) { Config.Instance.AvatarsInGame = value; };
114-
115-
116-
var NetworkQuality = settingsMenu.AddInt("Network Quality", 0, 5, 1);
114+
115+
var NetworkQuality = settingsMenu.AddInt("Network Quality", "Higher number, smoother avatar. Note that this effects how you appear to others. ", 0, 5, 1);
117116
NetworkQuality.GetValue += delegate { return Config.Instance.NetworkQuality; };
118117
NetworkQuality.SetValue += delegate (int value) {
119118
Config.Instance.NetworkQuality = value;
@@ -124,10 +123,9 @@ private void CreateSettingsMenu()
124123
}
125124
};
126125

127-
128-
var DebugMode = settingsMenu.AddBool("Debug Mode");
129-
DebugMode.GetValue += delegate { return Config.Instance.DebugMode; };
130-
DebugMode.SetValue += delegate (bool value) { Config.Instance.DebugMode = value; };
126+
var NetworkScaling = settingsMenu.AddBool("Network Scaling", "Scales your network traffic based on the size of your lobby.");
127+
NetworkScaling.GetValue += delegate { return Config.Instance.NetworkScaling; };
128+
NetworkScaling.SetValue += delegate (bool value) { Config.Instance.NetworkScaling = value; };
131129
}
132130

133131
private void CreateMainMenuButton()

0 commit comments

Comments
 (0)