mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-11-07 17:36:07 +00:00
ConsoleIcon support Windows 10 on new Console & OnLatencyUpdate Event (#1044)
* new ConsoleIcon support * Update ChatBot.cs + OnLatencyUpdate * Update McTcpClient.cs + OnLatencyUpdate * Update Protocol18.cs + OnLatencyUpdate * Update IMinecraftComHandler.cs + OnLatencyUpdate * Update Protocol18.cs + BugFix * Update ConsoleIcon.cs
This commit is contained in:
parent
85f5117833
commit
b800bbcb37
5 changed files with 65 additions and 4 deletions
|
|
@ -212,6 +212,14 @@ namespace MinecraftClient
|
|||
/// <param name="uuid">Player UUID</param>
|
||||
/// <param name="gamemode">New Game Mode (0: Survival, 1: Creative, 2: Adventure, 3: Spectator).</param>
|
||||
public virtual void OnGamemodeUpdate(string playername, Guid uuid, int gamemode) { }
|
||||
|
||||
/// <summary>
|
||||
/// Called when the Latency has been updated for a player
|
||||
/// </summary>
|
||||
/// <param name="playername">Player Name</param>
|
||||
/// <param name="uuid">Player UUID</param>
|
||||
/// <param name="latency">Latency.</param>
|
||||
public virtual void OnLatencyUpdate(string playername, Guid uuid, int latency) { }
|
||||
|
||||
/* =================================================================== */
|
||||
/* ToolBox - Methods below might be useful while creating your bot. */
|
||||
|
|
|
|||
|
|
@ -1635,7 +1635,23 @@ namespace MinecraftClient
|
|||
foreach (ChatBot bot in bots.ToArray())
|
||||
bot.OnExplosion(location, strength, affectedBlocks);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Called when Latency is updated
|
||||
/// </summary>
|
||||
/// <param name="uuid">player uuid</param>
|
||||
/// <param name="latency">Latency</param>
|
||||
public void OnLatencyUpdate(Guid uuid, int latency)
|
||||
{
|
||||
string playerName = null;
|
||||
if (onlinePlayers.ContainsKey(uuid))
|
||||
{
|
||||
playerName = onlinePlayers[uuid];
|
||||
foreach (ChatBot bot in bots.ToArray())
|
||||
bot.OnLatencyUpdate(playerName, uuid, latency);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called when Experience bar is updated
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -448,7 +448,8 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
handler.OnGamemodeUpdate(uuid, gamemode);
|
||||
break;
|
||||
case 0x02: //Update latency
|
||||
dataTypes.ReadNextVarInt(packetData);
|
||||
int latency = dataTypes.ReadNextVarInt(packetData);
|
||||
handler.OnLatencyUpdate(uuid, latency); //Update latency;
|
||||
break;
|
||||
case 0x03: //Update display name
|
||||
if (dataTypes.ReadNextBool(packetData))
|
||||
|
|
@ -1390,6 +1391,8 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
Container inventory = handler.GetInventory(windowId);
|
||||
if (inventory.Items.ContainsKey(slotId))
|
||||
inventory.Items[slotId].Count--; // server won't update us after dropped
|
||||
if (inventory.Items[slotId].Count == 0)
|
||||
inventory.Items.Remove(slotId);
|
||||
break;
|
||||
case WindowActionType.DropItemStack:
|
||||
button = 1;
|
||||
|
|
|
|||
|
|
@ -222,7 +222,14 @@ namespace MinecraftClient.Protocol
|
|||
/// <param name="uuid">Affected player's UUID</param>
|
||||
/// <param name="gamemode">New game mode</param>
|
||||
void OnGamemodeUpdate(Guid uuid, int gamemode);
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Called when a player's latency has changed
|
||||
/// </summary>
|
||||
/// <param name="uuid">Affected player's UUID</param>
|
||||
/// <param name="latency">latency</param>
|
||||
void OnLatencyUpdate(Guid uuid, int latency);
|
||||
|
||||
/// <summary>
|
||||
/// Called when Experience bar is updated
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -21,6 +21,32 @@ namespace MinecraftClient.WinAPI
|
|||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool SetConsoleIcon(IntPtr hIcon);
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously download the player's skin and set the head as console icon
|
||||
/// </summary>
|
||||
public enum WinMessages : uint
|
||||
{
|
||||
/// <summary>
|
||||
/// An application sends the WM_SETICON message to associate a new large or small icon with a window.
|
||||
/// The system displays the large icon in the ALT+TAB dialog box, and the small icon in the window caption.
|
||||
/// </summary>
|
||||
SETICON = 0x0080,
|
||||
}
|
||||
|
||||
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
|
||||
private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, IntPtr lParam);
|
||||
|
||||
|
||||
private static void SetWindowIcon(System.Drawing.Icon icon)
|
||||
{
|
||||
IntPtr mwHandle = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
|
||||
IntPtr result01 = SendMessage(mwHandle, (int)WinMessages.SETICON, 0, icon.Handle);
|
||||
IntPtr result02 = SendMessage(mwHandle, (int)WinMessages.SETICON, 1, icon.Handle);
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
private static extern bool SetConsoleIcon(IntPtr hIcon);
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously download the player's skin and set the head as console icon
|
||||
/// </summary>
|
||||
|
|
@ -31,7 +57,7 @@ namespace MinecraftClient.WinAPI
|
|||
{
|
||||
Thread t = new Thread(new ThreadStart(delegate
|
||||
{
|
||||
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("http://skins.minecraft.net/MinecraftSkins/" + playerName + ".png");
|
||||
HttpWebRequest httpWebRequest = (HttpWebRequest)HttpWebRequest.Create("https://minotar.net/helm/" + playerName + "/100.png");
|
||||
try
|
||||
{
|
||||
using (HttpWebResponse httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse())
|
||||
|
|
@ -40,6 +66,7 @@ namespace MinecraftClient.WinAPI
|
|||
{
|
||||
Bitmap skin = new Bitmap(Image.FromStream(httpWebReponse.GetResponseStream())); //Read skin from network
|
||||
skin = skin.Clone(new Rectangle(8, 8, 8, 8), skin.PixelFormat); //Crop skin
|
||||
SetWindowIcon(Icon.FromHandle(skin.GetHicon()));
|
||||
SetConsoleIcon(skin.GetHicon()); //Set skin as icon
|
||||
}
|
||||
catch (ArgumentException) { /* Invalid image in HTTP response */ }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue