diff --git a/LobbyCompatibility/Behaviours/ModdedLobbySlot.cs b/LobbyCompatibility/Behaviours/ModdedLobbySlot.cs index da2dccc..d376d87 100644 --- a/LobbyCompatibility/Behaviours/ModdedLobbySlot.cs +++ b/LobbyCompatibility/Behaviours/ModdedLobbySlot.cs @@ -30,7 +30,8 @@ internal void Setup(LobbySlot lobbySlot) _lobbySlot = lobbySlot; // Get the "diff" of the lobby - _lobbyDiff = LobbyHelper.GetLobbyDiff(_lobbySlot.thisLobby); + if (_lobbyDiff == null || !GameNetworkManager.Instance || !GameNetworkManager.Instance.disableSteam) + _lobbyDiff = LobbyHelper.GetLobbyDiff(_lobbySlot.thisLobby); // Find player count text (could be moved/removed in a future update, but unlikely) var playerCount = _lobbySlot.playerCount; diff --git a/LobbyCompatibility/Features/LobbyHelper.cs b/LobbyCompatibility/Features/LobbyHelper.cs index 1ec7c70..00d108d 100644 --- a/LobbyCompatibility/Features/LobbyHelper.cs +++ b/LobbyCompatibility/Features/LobbyHelper.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; @@ -27,7 +28,7 @@ public static class LobbyHelper /// /// The lobby to get the diff from. /// The from the . - public static LobbyDiff GetLobbyDiff(Lobby lobby) => GetLobbyDiff(lobby, null); + public static LobbyDiff GetLobbyDiff(Lobby? lobby) => GetLobbyDiff(lobby, null); /// /// Get a from a or . @@ -35,16 +36,16 @@ public static class LobbyHelper /// The lobby to cache the diff to and/or get the diff from. /// The json string to parse. /// The . - internal static LobbyDiff GetLobbyDiff(Lobby lobby, string? lobbyPluginString) + internal static LobbyDiff GetLobbyDiff(Lobby? lobby, string? lobbyPluginString) { - if (LobbyDiffCache.TryGetValue(lobby.Id, out var cachedLobbyDiff)) + if (lobby.HasValue && LobbyDiffCache.TryGetValue(lobby.Value.Id, out var cachedLobbyDiff)) { LatestLobbyDiff = cachedLobbyDiff; return cachedLobbyDiff; } var lobbyPlugins = PluginHelper - .ParseLobbyPluginsMetadata(lobbyPluginString ?? GetLobbyPlugins(lobby)).ToList(); + .ParseLobbyPluginsMetadata(lobbyPluginString ?? (lobby.HasValue ? GetLobbyPlugins(lobby.Value) : string.Empty)).ToList(); _clientPlugins ??= PluginHelper.GetAllPluginInfo().ToList(); var pluginDiffs = new List(); @@ -119,7 +120,8 @@ internal static LobbyDiff GetLobbyDiff(Lobby lobby, string? lobbyPluginString) LatestLobbyDiff = new LobbyDiff(pluginDiffs, lobbyCompatibilityPresent); // Add to cache to avoid making multiple unnecessary GetData() calls - LobbyDiffCache.Add(lobby.Id, LatestLobbyDiff); + if (lobby.HasValue) + LobbyDiffCache.Add(lobby.Value.Id, LatestLobbyDiff); return LatestLobbyDiff; } @@ -132,10 +134,13 @@ internal static LobbyDiff GetLobbyDiff(Lobby lobby, string? lobbyPluginString) internal static string GetLobbyPlugins(Lobby lobby) { var lobbyPluginStrings = new List(); - var i = 0; - do lobbyPluginStrings.Insert(i, lobby.GetData($"{LobbyMetadata.Plugins}{i}")); - while (lobbyPluginStrings[i++].Contains("@")); + if (GameNetworkManager.Instance && !GameNetworkManager.Instance.disableSteam) + { + var i = 0; + do lobbyPluginStrings.Insert(i, lobby.GetData($"{LobbyMetadata.Plugins}{i}")); + while (lobbyPluginStrings[i++].Contains("@")); + } return lobbyPluginStrings .Join(delimiter: string.Empty) diff --git a/LobbyCompatibility/Patches/MenuManagerPostfix.cs b/LobbyCompatibility/Patches/MenuManagerPostfix.cs index e2b1215..bdfdc0e 100644 --- a/LobbyCompatibility/Patches/MenuManagerPostfix.cs +++ b/LobbyCompatibility/Patches/MenuManagerPostfix.cs @@ -72,6 +72,7 @@ private static void Postfix(MenuManager __instance) UIHelper.ReskinRefreshButton(refreshButton); // Add a custom "Mods" filtering type, and shift all other filtering UI elements to the left - UIHelper.AddCustomFilterToLobbyList(listPanel); + if (!GameNetworkManager.Instance || !GameNetworkManager.Instance.disableSteam) + UIHelper.AddCustomFilterToLobbyList(listPanel); } } \ No newline at end of file diff --git a/LobbyCompatibility/Patches/StartAClientPostfix.cs b/LobbyCompatibility/Patches/StartAClientPostfix.cs new file mode 100644 index 0000000..b32eea9 --- /dev/null +++ b/LobbyCompatibility/Patches/StartAClientPostfix.cs @@ -0,0 +1,22 @@ +using HarmonyLib; +using LobbyCompatibility.Features; + +namespace LobbyCompatibility.Patches; + +/// +/// Patches . +/// Checks if required plugins are present in the lobby metadata and are the same version as the client. +/// +/// +[HarmonyPatch(typeof(MenuManager), nameof(MenuManager.StartAClient))] +[HarmonyPriority(Priority.Last)] +[HarmonyWrapSafe] +internal static class StartAClientPostfix +{ + [HarmonyPrefix] + private static void Prefix() + { + // Create lobby diff so LatestLobbyDiff is set + LobbyHelper.GetLobbyDiff(null); + } +} \ No newline at end of file