diff --git a/CopiedLobbyMess/Configuration.cs b/CopiedLobbyMess/Configuration.cs index f7f91ad..a11c0d8 100644 --- a/CopiedLobbyMess/Configuration.cs +++ b/CopiedLobbyMess/Configuration.cs @@ -28,7 +28,7 @@ public class Configuration : IRocketPluginConfiguration public string CameraMode; public bool GoldOnly; public bool HasBattleye; - public bool IsVannila; + public bool IsVanilla; public void LoadDefaults() { @@ -39,7 +39,7 @@ public void LoadDefaults() { "Plugins removed by", "CopiedLobbyMess", - "Thanks AtiLion" + "AtiLion is gay" }; HideWorkshop = true; @@ -57,11 +57,11 @@ public void LoadDefaults() MessConfig = false; IsPVP = true; HasCheats = false; - Difficulty = "NORMAL"; - CameraMode = "BOTH"; + Difficulty = "NRM"; + CameraMode = "2p"; GoldOnly = false; HasBattleye = true; - IsVannila = false; + IsVanilla = false; } } } diff --git a/CopiedLobbyMess/CopiedLobbyMess.cs b/CopiedLobbyMess/CopiedLobbyMess.cs index abd2c25..a00bcff 100644 --- a/CopiedLobbyMess/CopiedLobbyMess.cs +++ b/CopiedLobbyMess/CopiedLobbyMess.cs @@ -14,178 +14,104 @@ namespace CopiedLobbyMess { public class CopiedLobbyMess : RocketPlugin { - #region Properties - public static CopiedLobbyMess Instance { get; private set; } - #endregion - protected override void Load() { - R.Plugins.OnPluginsLoaded += OnLoad; - } + if (Level.isLoaded) + ModifyLobbyInfo(); - protected override void Unload() - { - R.Plugins.OnPluginsLoaded -= OnLoad; + Level.onPostLevelLoaded += OnPostLevelLoaded; } + protected override void Unload() => Level.onPostLevelLoaded -= OnPostLevelLoaded; + #region Functions - public int GetWorkshopCount() - { - string text = string.Empty; - for (int l = 0; l < Provider.serverWorkshopFileIDs.Count; l++) - { - if (text.Length > 0) - { - text += ','; - } - text += Provider.serverWorkshopFileIDs[l]; - } - return (text.Length - 1) / 120 + 1; - } + public static int GetWorkshopCount() => + (String.Join(",", Provider.serverWorkshopFileIDs.Select(x => x.ToString()).ToArray()).Length - 1) / 120 + 1; - public int GetConfigurationCount() - { - string text2 = string.Empty; - Type type = Provider.modeConfigData.GetType(); - FieldInfo[] fields = type.GetFields(); - for (int n = 0; n < fields.Length; n++) - { - FieldInfo fieldInfo = fields[n]; - object value = fieldInfo.GetValue(Provider.modeConfigData); - Type type2 = value.GetType(); - FieldInfo[] fields2 = type2.GetFields(); - for (int num7 = 0; num7 < fields2.Length; num7++) - { - FieldInfo fieldInfo2 = fields2[num7]; - object value2 = fieldInfo2.GetValue(value); - if (text2.Length > 0) - { - text2 += ','; - } - if (value2 is bool) - { - text2 += ((!(bool)value2) ? "F" : "T"); - } - else - { - text2 += value2; - } - } - } - return (text2.Length - 1) / 120 + 1; - } + public static int GetConfigurationCount() => + (String.Join(",", typeof(ModeConfigData).GetFields() + .SelectMany(x => x.GetValue(Provider.modeConfigData).GetType().GetFields().Select(y => y.GetValue(x.GetValue(Provider.modeConfigData)))) + .Select(x => x is bool v ? v ? "T" : "F" : (String.Empty + x)).ToArray()).Length - 1) / 120 + 1; + + + public void OnPostLevelLoaded(int xd) => ModifyLobbyInfo(); - public void ModifyGameTags() + private void ModifyLobbyInfo() { - string tags = ""; + bool workshop = Provider.serverWorkshopFileIDs.Count > 0; #region Workshop if (Configuration.Instance.HideWorkshop) { - tags += "KROW"; // No workshop + workshop = false; SteamGameServer.SetKeyValue("Browser_Workshop_Count", "0"); } else if (Configuration.Instance.MessWorkshop) { - tags += "WORK"; // Workshop - - string txt = ""; - foreach(string a in Configuration.Instance.Workshop) - { - if (txt.Length > 0) - txt += ","; - txt += a; - } + workshop = true; + string txt = String.Join(",", Configuration.Instance.Workshop); SteamGameServer.SetKeyValue("Browser_Workshop_Count", ((txt.Length - 1) / 120 + 1).ToString()); - int num5 = 0; - for (int m = 0; m < txt.Length; m += 120) + int line = 0; + for (int i = 0; i < txt.Length; i += 120) { int num6 = 120; - if (m + num6 > txt.Length) - { - num6 = txt.Length - m; - } - string pValue2 = txt.Substring(m, num6); - SteamGameServer.SetKeyValue("Browser_Workshop_Line_" + num5, pValue2); - num5++; + + if (i + num6 > txt.Length) + num6 = txt.Length - i; + + string pValue2 = txt.Substring(i, num6); + SteamGameServer.SetKeyValue("Browser_Workshop_Line_" + line, pValue2); + line++; } } else { - if(Provider.serverWorkshopFileIDs.Count <= 0) - { - tags += "KROW"; - } - else - { - tags += "WORK"; // Workshop - SteamGameServer.SetKeyValue("Browser_Workshop_Count", GetWorkshopCount().ToString()); - } + SteamGameServer.SetKeyValue("Browser_Workshop_Count", GetWorkshopCount().ToString()); } #endregion - #region Gamemode - if (Configuration.Instance.MessGamemode) - tags += ",GAMEMODE:" + Configuration.Instance.Gamemode; - else if (Provider.gameMode != null) - tags += ",GAMEMODE:" + Provider.gameMode.GetType().Name; - #endregion - #region Config + string tags = ""; + if (Configuration.Instance.MessConfig) { - tags += ","; - if (Configuration.Instance.IsPVP) - tags += "PVP"; - else - tags += "PVE"; - tags += ","; - if (Configuration.Instance.HasCheats) - tags += "CHEATS"; - else - tags += "STAEHC"; - tags += ","; - tags += Configuration.Instance.Difficulty; - tags += ","; - tags += Configuration.Instance.CameraMode; - tags += ","; - if (Configuration.Instance.GoldOnly) - tags += "GOLDONLY"; - else - tags += "YLNODLOG"; - tags += ","; - if (Configuration.Instance.HasBattleye) - tags += "BATTLEYE_ON"; - else - tags += "BATTLEYE_OFF"; - } - else - { - tags += ","; - tags += (!Provider.isPvP) ? "PVE" : "PVP"; - tags += ","; - tags += (!Provider.hasCheats) ? "STAEHC" : "CHEATS"; - tags += ","; - tags += Provider.mode.ToString(); - tags += ","; - tags += Provider.cameraMode.ToString(); - tags += ","; - tags += (!Provider.isGold) ? "YLNODLOG" : "GOLDONLY"; - tags += ","; - tags += (!Provider.configData.Server.BattlEye_Secure) ? "BATTLEYE_OFF" : "BATTLEYE_ON"; + tags += String.Concat(new string[] + { + Configuration.Instance.IsPVP ? "PVP" : "PVE", + ",", + Configuration.Instance.MessGamemode ? Configuration.Instance.Gamemode : Provider.gameMode.GetType().Name, + ",", + Configuration.Instance.HasCheats ? "CHy" : "CHn", + ",", + Configuration.Instance.Difficulty, + ",", + Configuration.Instance.CameraMode, + ",", + workshop ? "WSn" : "WSy", + ",", + Configuration.Instance.GoldOnly ? "GLD" : "F2P", + ",", + Configuration.Instance.HasBattleye ? "BEy" : "BEn" + }); + + if (!String.IsNullOrEmpty(Provider.configData.Browser.Thumbnail)) + tags += "," + Provider.configData.Browser.Thumbnail + ""; + + + SteamGameServer.SetGameTags(tags); } + #endregion #region Configuration + if (Configuration.Instance.HideConfig) SteamGameServer.SetKeyValue("Browser_Config_Count", "0"); else SteamGameServer.SetKeyValue("Browser_Config_Count", GetConfigurationCount().ToString()); #endregion - SteamGameServer.SetGameTags(tags); - #region Plugins if (Configuration.Instance.InvisibleRocket) SteamGameServer.SetBotPlayerCount(0); // Bypasses unturned's filter for rocket <3 @@ -202,7 +128,7 @@ public void ModifyGameTags() SteamGameServer.SetKeyValue("rocketplugins", ""); } - if (Configuration.Instance.IsVannila) + if (Configuration.Instance.IsVanilla) { SteamGameServer.SetBotPlayerCount(0); SteamGameServer.SetKeyValue("rocketplugins", ""); @@ -214,17 +140,11 @@ public void ModifyGameTags() SteamGameServer.SetBotPlayerCount(1); if (!Configuration.Instance.HidePlugins && !Configuration.Instance.MessPlugins) SteamGameServer.SetKeyValue("rocketplugins", string.Join(",", R.Plugins.GetPlugins().Select(p => p.Name).ToArray())); - SteamGameServer.SetKeyValue("rocket", ModuleHook.modules.FirstOrDefault(a => a.config.Name == "Rocket.Unturned").config.Version); + string version = ModuleHook.modules.FirstOrDefault(a => a.config.Name == "Rocket.Unturned")?.config.Version ?? "0.0.0.69"; + SteamGameServer.SetKeyValue("rocket", version); } #endregion } #endregion - - #region Event Functions - void OnLoad() - { - ModifyGameTags(); - } - #endregion } }