From e81700bf0e683d2e4b4534e77b3b4d9edfceb690 Mon Sep 17 00:00:00 2001 From: BruceChen Date: Mon, 6 Apr 2026 20:32:38 +0800 Subject: [PATCH] Fix warnings --- MinecraftClient/Crypto/FastAes.cs | 30 +++++++++++------------- MinecraftClient/Program.cs | 2 +- MinecraftClient/Scripting/MccGameApi.cs | 6 ++--- MinecraftClient/Tui/TuiConsoleBackend.cs | 3 --- MinecraftClient/WinAPI/ConsoleIcon.cs | 26 ++++++++------------ 5 files changed, 28 insertions(+), 39 deletions(-) diff --git a/MinecraftClient/Crypto/FastAes.cs b/MinecraftClient/Crypto/FastAes.cs index 41de7d54..e423caab 100644 --- a/MinecraftClient/Crypto/FastAes.cs +++ b/MinecraftClient/Crypto/FastAes.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Intrinsics; @@ -63,16 +63,16 @@ namespace MinecraftClient.Crypto keys[0] = Unsafe.ReadUnaligned>(ref key[0]); - MakeRoundKey(keys, 1, 0x01); - MakeRoundKey(keys, 2, 0x02); - MakeRoundKey(keys, 3, 0x04); - MakeRoundKey(keys, 4, 0x08); - MakeRoundKey(keys, 5, 0x10); - MakeRoundKey(keys, 6, 0x20); - MakeRoundKey(keys, 7, 0x40); - MakeRoundKey(keys, 8, 0x80); - MakeRoundKey(keys, 9, 0x1b); - MakeRoundKey(keys, 10, 0x36); + ExpandRound(keys, 1, Aes.KeygenAssist(keys[0], 0x01)); + ExpandRound(keys, 2, Aes.KeygenAssist(keys[1], 0x02)); + ExpandRound(keys, 3, Aes.KeygenAssist(keys[2], 0x04)); + ExpandRound(keys, 4, Aes.KeygenAssist(keys[3], 0x08)); + ExpandRound(keys, 5, Aes.KeygenAssist(keys[4], 0x10)); + ExpandRound(keys, 6, Aes.KeygenAssist(keys[5], 0x20)); + ExpandRound(keys, 7, Aes.KeygenAssist(keys[6], 0x40)); + ExpandRound(keys, 8, Aes.KeygenAssist(keys[7], 0x80)); + ExpandRound(keys, 9, Aes.KeygenAssist(keys[8], 0x1b)); + ExpandRound(keys, 10, Aes.KeygenAssist(keys[9], 0x36)); for (int i = 1; i < 10; i++) { @@ -82,13 +82,11 @@ namespace MinecraftClient.Crypto return keys; } - private static void MakeRoundKey(Vector128[] keys, int i, byte rcon) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static void ExpandRound(Vector128[] keys, int i, Vector128 assist) { Vector128 s = keys[i - 1]; - Vector128 t = keys[i - 1]; - - t = Aes.KeygenAssist(t, rcon); - t = Sse2.Shuffle(t.AsUInt32(), 0xFF).AsByte(); + Vector128 t = Sse2.Shuffle(assist.AsUInt32(), 0xFF).AsByte(); s = Sse2.Xor(s, Sse2.ShiftLeftLogical128BitLane(s, 4)); s = Sse2.Xor(s, Sse2.ShiftLeftLogical128BitLane(s, 8)); diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 91c9ffb1..ae706296 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -951,7 +951,7 @@ namespace MinecraftClient offlinePrompt = null; ConsoleIO.Reset(); } - if (Config.Main.Advanced.PlayerHeadAsIcon) { ConsoleIcon.RevertToMCCIcon(); } + if (Config.Main.Advanced.PlayerHeadAsIcon && OperatingSystem.IsWindows()) { ConsoleIcon.RevertToMCCIcon(); } ConsoleIO.Backend?.Shutdown(); Environment.Exit(exitcode); } diff --git a/MinecraftClient/Scripting/MccGameApi.cs b/MinecraftClient/Scripting/MccGameApi.cs index 391ece50..b7c8fbbd 100644 --- a/MinecraftClient/Scripting/MccGameApi.cs +++ b/MinecraftClient/Scripting/MccGameApi.cs @@ -803,7 +803,7 @@ public sealed class MccGameApi { Id = inventory.ID, Type = inventory.Type.ToString(), - Title = inventory.Title, + Title = inventory.Title ?? string.Empty, SlotCount = inventory.Type.SlotCount(), Slots = slots, Cursor = TryBuildCursorSnapshot(inventory) @@ -850,7 +850,7 @@ public sealed class MccGameApi { InventoryId = entry.Key, InventoryType = inventory.Type.ToString(), - InventoryTitle = inventory.Title, + InventoryTitle = inventory.Title ?? string.Empty, Slot = pair.Key, ItemType = pair.Value.Type.ToString(), TypeLabel = pair.Value.GetTypeString(), @@ -894,7 +894,7 @@ public sealed class MccGameApi { Id = entry.Key, Type = entry.Value.Type.ToString(), - Title = entry.Value.Title, + Title = entry.Value.Title ?? string.Empty, SlotCount = entry.Value.Type.SlotCount(), NonEmptySlots = entry.Value.Items.Count(item => IsSnapshotInventorySlot(entry.Value, item.Key)), Active = entry.Key > 0 && entry.Key == GetActiveContainerId(client) diff --git a/MinecraftClient/Tui/TuiConsoleBackend.cs b/MinecraftClient/Tui/TuiConsoleBackend.cs index bee59751..58bd444d 100644 --- a/MinecraftClient/Tui/TuiConsoleBackend.cs +++ b/MinecraftClient/Tui/TuiConsoleBackend.cs @@ -19,7 +19,6 @@ namespace MinecraftClient.Tui public event EventHandler? OnInputChange; private MainTuiView? _view; - private volatile bool _readThreadActive; public bool DisplayUserInput { get; set; } = true; @@ -177,12 +176,10 @@ namespace MinecraftClient.Tui public void BeginReadThread() { - _readThreadActive = true; } public void StopReadThread() { - _readThreadActive = false; DismissOverlay(); } diff --git a/MinecraftClient/WinAPI/ConsoleIcon.cs b/MinecraftClient/WinAPI/ConsoleIcon.cs index e66eca89..cc243dda 100644 --- a/MinecraftClient/WinAPI/ConsoleIcon.cs +++ b/MinecraftClient/WinAPI/ConsoleIcon.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Drawing; using System.IO; using System.Net.Http; @@ -13,6 +13,7 @@ namespace MinecraftClient.WinAPI /// Allow to set the player skin as console icon, on Windows only. /// See StackOverflow no. 2986853 /// + [SupportedOSPlatform("windows")] public static class ConsoleIcon { [DllImport("kernel32.dll", SetLastError = true)] @@ -32,18 +33,14 @@ namespace MinecraftClient.WinAPI private static void SetWindowIcon(System.Drawing.Icon icon) { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - IntPtr mwHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; - SendMessage(mwHandle, (int)WinMessages.SETICON, 0, icon.Handle); - SendMessage(mwHandle, (int)WinMessages.SETICON, 1, icon.Handle); - } + IntPtr mwHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle; + SendMessage(mwHandle, (int)WinMessages.SETICON, 0, icon.Handle); + SendMessage(mwHandle, (int)WinMessages.SETICON, 1, icon.Handle); } /// /// Asynchronously download the player's skin and set the head as console icon /// - [SupportedOSPlatform("windows")] public static void SetPlayerIconAsync(string playerName) { Thread t = new(new ThreadStart(delegate @@ -99,16 +96,13 @@ namespace MinecraftClient.WinAPI /// public static void RevertToMCCIcon() { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) //Windows Only + try { - try - { - Icon defaultIcon = Icon.ExtractAssociatedIcon(Environment.ProcessPath!)!; - SetWindowIcon(Icon.FromHandle(defaultIcon.Handle)); // Windows 10+ (New console) - SetConsoleIcon(defaultIcon.Handle); // Windows 8 and lower (Older console) - } - catch { } + Icon defaultIcon = Icon.ExtractAssociatedIcon(Environment.ProcessPath!)!; + SetWindowIcon(Icon.FromHandle(defaultIcon.Handle)); // Windows 10+ (New console) + SetConsoleIcon(defaultIcon.Handle); // Windows 8 and lower (Older console) } + catch { } } } }