diff --git a/XLMultiplayer/Main.cs b/XLMultiplayer/Main.cs index ab0327f..46d19e9 100644 --- a/XLMultiplayer/Main.cs +++ b/XLMultiplayer/Main.cs @@ -457,9 +457,13 @@ public static IEnumerator StartUpdatingServerList() { private static void ClickServerItem(ServerListItem target) { if(!serverClickWatch.IsRunning || serverClickWatch.Elapsed.TotalMilliseconds > 1000f) { - UnityModManager.Logger.Log($"Attempting to connect to server {target.ServerName.text} with ip {target.ipAddress} port {target.port}"); - JoinServer(target.ipAddress, target.port, NewMultiplayerMenu.Instance.usernameFields[0].text); - serverClickWatch.Restart(); + if (target.ServerVersion.text.Trim().ToLower().Equals(modEntry.Version.ToString())) { + UnityModManager.Logger.Log($"Attempting to connect to server {target.ServerName.text} with ip {target.ipAddress} port {target.port}"); + JoinServer(target.ipAddress, target.port, NewMultiplayerMenu.Instance.usernameFields[0].text); + serverClickWatch.Restart(); + } else { + utilityMenu.SendImportantChat($"Unable to connect to server because it's version {target.ServerVersion.text} does not match client version {modEntry.Version.ToString()}", 15000); + } } } @@ -609,7 +613,7 @@ private static void DisplayVolume() { } [HarmonyPatch(typeof(ReplayEditorController), "OnDisable")] - static class MultiplayReplayDisablePatch { + static class Multiplay34ReplayDisablePatch { static void Prefix() { if (Main.multiplayerController != null) { foreach (MultiplayerRemotePlayerController controller in Main.multiplayerController.remoteControllers) { @@ -639,7 +643,7 @@ static bool Prefix(ReplayPlaybackController __instance) { } [HarmonyPatch(typeof(ReplayEditorController), "Update")] - static class MultiplayReplayUpdatePatch { + static class MultiplayerReplayUpdatePatch { static void Postfix(ReplayEditorController __instance) { foreach (MultiplayerRemotePlayerController controller in Main.remoteReplayControllers) { controller.replayController.TimeScale = ReplayEditorController.Instance.playbackController.TimeScale; diff --git a/XLMultiplayer/MultiplayerUtilityMenu.cs b/XLMultiplayer/MultiplayerUtilityMenu.cs index da00f86..f820fb8 100644 --- a/XLMultiplayer/MultiplayerUtilityMenu.cs +++ b/XLMultiplayer/MultiplayerUtilityMenu.cs @@ -165,16 +165,18 @@ private void DisplayChat(int windowId) { } chatStyle2.wordWrap = true; - if (Main.multiplayerController.chatMessages != null && Main.multiplayerController.chatMessages.Count > 0) { - int difference = Main.multiplayerController.chatMessages.Count - previousMessageCount; - float scrollDifference = 0f; - for (int i = Main.multiplayerController.chatMessages.Count - difference; i < Main.multiplayerController.chatMessages.Count; i++) { - chat += Main.multiplayerController.chatMessages[i] + "\n"; - scrollDifference += chatStyle2.CalcHeight(new GUIContent(Main.multiplayerController.chatMessages[i]), chatWindowRect.width - 26) / chatStyle2.CalcHeight(new GUIContent("a"), chatWindowRect.width - 26) * chatStyle2.lineHeight; + if (Main.multiplayerController != null) { + if (Main.multiplayerController.chatMessages != null && Main.multiplayerController.chatMessages.Count > 0) { + int difference = Main.multiplayerController.chatMessages.Count - previousMessageCount; + float scrollDifference = 0f; + for (int i = Main.multiplayerController.chatMessages.Count - difference; i < Main.multiplayerController.chatMessages.Count; i++) { + chat += Main.multiplayerController.chatMessages[i] + "\n"; + scrollDifference += chatStyle2.CalcHeight(new GUIContent(Main.multiplayerController.chatMessages[i]), chatWindowRect.width - 26) / chatStyle2.CalcHeight(new GUIContent("a"), chatWindowRect.width - 26) * chatStyle2.lineHeight; + } + previousMessageCount = Main.multiplayerController.chatMessages.Count; + if (chatStyle2.CalcHeight(new GUIContent(chat), chatWindowRect.width - 26) > chatWindowRect.height - 43) + chatScrollPosition.y += scrollDifference; } - previousMessageCount = Main.multiplayerController.chatMessages.Count; - if (chatStyle2.CalcHeight(new GUIContent(chat), chatWindowRect.width - 26) > chatWindowRect.height - 43) - chatScrollPosition.y += scrollDifference; } // Create the chat window