diff --git a/MinecraftClient/ChatBots/Map.cs b/MinecraftClient/ChatBots/Map.cs index 25e75a74..c0c3aa8e 100644 --- a/MinecraftClient/ChatBots/Map.cs +++ b/MinecraftClient/ChatBots/Map.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; @@ -344,8 +344,11 @@ namespace MinecraftClient.ChatBots private static void RenderInConsole(McMap map) { StringBuilder sb = new(); - int consoleWidth = Math.Max(Console.BufferWidth, Settings.Config.Main.Advanced.MinTerminalWidth) / 2; - int consoleHeight = Math.Max(Console.BufferHeight, Settings.Config.Main.Advanced.MinTerminalHeight) - 1; + int safeBufWidth, safeBufHeight; + try { safeBufWidth = Console.BufferWidth; } catch { safeBufWidth = 120; } + try { safeBufHeight = Console.BufferHeight; } catch { safeBufHeight = 50; } + int consoleWidth = Math.Max(safeBufWidth, Settings.Config.Main.Advanced.MinTerminalWidth) / 2; + int consoleHeight = Math.Max(safeBufHeight, Settings.Config.Main.Advanced.MinTerminalHeight) - 1; int scaleX = (map.Width + consoleWidth - 1) / consoleWidth; int scaleY = (map.Height + consoleHeight - 1) / consoleHeight; int scale = Math.Max(scaleX, scaleY); diff --git a/MinecraftClient/Commands/Chunk.cs b/MinecraftClient/Commands/Chunk.cs index cdc26e14..2068c662 100644 --- a/MinecraftClient/Commands/Chunk.cs +++ b/MinecraftClient/Commands/Chunk.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Text; using Brigadier.NET; using Brigadier.NET.Builder; @@ -100,11 +100,15 @@ namespace MinecraftClient.Commands sb.AppendLine(string.Format(Translations.cmd_chunk_chunk_pos, markChunkX, markChunkZ)); ; } - int consoleHeight = Math.Max(Math.Max(Console.BufferHeight, Settings.Config.Main.Advanced.MinTerminalHeight) - 2, 25); + int safeHeight; + int safeWidth; + try { safeHeight = Console.BufferHeight; } catch { safeHeight = 50; } + try { safeWidth = Console.BufferWidth; } catch { safeWidth = 120; } + int consoleHeight = Math.Max(Math.Max(safeHeight, Settings.Config.Main.Advanced.MinTerminalHeight) - 2, 25); if (consoleHeight % 2 == 0) --consoleHeight; - int consoleWidth = Math.Max(Math.Max(Console.BufferWidth, Settings.Config.Main.Advanced.MinTerminalWidth) / 2, 17); + int consoleWidth = Math.Max(Math.Max(safeWidth, Settings.Config.Main.Advanced.MinTerminalWidth) / 2, 17); if (consoleWidth % 2 == 0) --consoleWidth; diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 1b68583d..b8a1f788 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Globalization; using System.IO; @@ -768,8 +768,10 @@ namespace MinecraftClient if (!String.IsNullOrEmpty(errorMessage)) { ConsoleIO.Reset(); - while (Console.KeyAvailable) - Console.ReadKey(true); + try { + while (Console.KeyAvailable) + Console.ReadKey(true); + } catch { } ConsoleIO.WriteLine(errorMessage); if (disconnectReason.HasValue) diff --git a/MinecraftClient/Protocol/ReplayHandler.cs b/MinecraftClient/Protocol/ReplayHandler.cs index 75184e26..be567caf 100644 --- a/MinecraftClient/Protocol/ReplayHandler.cs +++ b/MinecraftClient/Protocol/ReplayHandler.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -239,8 +239,8 @@ namespace MinecraftClient.Protocol // format: timestamp + packetLength + RawPacket List line = new(); int nowTime = Convert.ToInt32((lastPacketTime - recordStartTime).TotalMilliseconds); - line.AddRange(BitConverter.GetBytes((Int32)nowTime).Reverse().ToArray()); - line.AddRange(BitConverter.GetBytes((Int32)rawPacket.Count).Reverse().ToArray()); + line.AddRange(BitConverter.GetBytes((Int32)nowTime).AsEnumerable().Reverse().ToArray()); + line.AddRange(BitConverter.GetBytes((Int32)rawPacket.Count).AsEnumerable().Reverse().ToArray()); line.AddRange(rawPacket.ToArray()); // Write out to the file recordStream!.Write(line.ToArray());