Bugfix: Send too many movement packets

This commit is contained in:
BruceChen 2022-10-04 12:34:37 +08:00 committed by GitHub
commit 1611f3c12c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 82 additions and 50 deletions

View file

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using MinecraftClient.Mapping;
namespace MinecraftClient.ChatBots
@ -63,11 +64,11 @@ namespace MinecraftClient.ChatBots
if (parts.Length == 2)
{
if (int.TryParse(parts[0].Trim(), out int firstTime))
if (int.TryParse(parts[0].Trim(), NumberStyles.Any, CultureInfo.CurrentCulture, out int firstTime))
{
timeping = firstTime;
if (int.TryParse(parts[1].Trim(), out int secondTime))
if (int.TryParse(parts[1].Trim(), NumberStyles.Any, CultureInfo.CurrentCulture, out int secondTime))
timepingMax = secondTime;
else LogToConsole(Translations.TryGet("bot.antiafk.invalid_range_partial", timeping));
}
@ -77,7 +78,7 @@ namespace MinecraftClient.ChatBots
}
else
{
if (int.TryParse(pingparam.Trim(), out int value))
if (int.TryParse(pingparam.Trim(), NumberStyles.Any, CultureInfo.CurrentCulture, out int value))
timeping = value;
else LogToConsole(Translations.TryGet("bot.antiafk.invalid_value"));
}

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using System.IO;
using MinecraftClient.Mapping;
using MinecraftClient.Protocol.Handlers;
@ -70,7 +71,7 @@ namespace MinecraftClient.ChatBots
if (args.Length < 2)
return "maps <list/render <id>> | maps <l/r <id>>";
if (int.TryParse(args[1], out int mapId))
if (int.TryParse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture, out int mapId))
{
if (!cachedMaps.ContainsKey(mapId))
return Translations.TryGet("bot.map.cmd.not_found", mapId);
@ -101,6 +102,9 @@ namespace MinecraftClient.ChatBots
if (columnsUpdated == 0 && cachedMaps.ContainsKey(mapid))
return;
if (rowsUpdated <= 0 && columnsUpdated <= 0)
return;
McMap map = new()
{
MapId = mapid,

View file

@ -84,8 +84,8 @@ namespace MinecraftClient.ChatBots
string[] parts = argValue.Split("-");
if (parts.Length == 2)
{
interval = int.Parse(parts[0].Trim());
intervalMax = int.Parse(parts[1].Trim());
interval = int.Parse(parts[0].Trim(), NumberStyles.Any, CultureInfo.CurrentCulture);
intervalMax = int.Parse(parts[1].Trim(), NumberStyles.Any, CultureInfo.CurrentCulture);
}
else
{
@ -94,7 +94,7 @@ namespace MinecraftClient.ChatBots
}
else
{
interval = int.Parse(argValue);
interval = int.Parse(argValue, NumberStyles.Any, CultureInfo.CurrentCulture);
}
current_task.triggerOnInterval_Interval = interval;

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using MinecraftClient.Mapping;
@ -30,7 +31,7 @@ namespace MinecraftClient.Commands
{
if (args.Length == 2)
{
if (!int.TryParse(args[1], out int radius))
if (!int.TryParse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture, out int radius))
return CmdUsage;
handler.GetLogger().Info(Translations.TryGet("cmd.bed.searching", radius));

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using MinecraftClient.Mapping;
@ -36,7 +37,10 @@ namespace MinecraftClient.Commands
{
sb.Append("Marked location: ");
if (args.Length == 1 + 3)
sb.Append(String.Format("X:{0:0.00} Y:{1:0.00} Z:{2:0.00}, ", double.Parse(args[1]), double.Parse(args[2]), double.Parse(args[3])));
sb.Append(String.Format("X:{0:0.00} Y:{1:0.00} Z:{2:0.00}, ",
double.Parse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture),
double.Parse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture),
double.Parse(args[3], NumberStyles.Any, CultureInfo.CurrentCulture)));
sb.Append(String.Format("chunk: ({0}, {1}).\n", markChunkX, markChunkZ));
}
@ -230,14 +234,18 @@ namespace MinecraftClient.Commands
int chunkX, chunkZ;
if (args.Length == 1 + 3)
{
Location pos = new(double.Parse(args[1]), double.Parse(args[2]), double.Parse(args[3]));
Location pos = new(
double.Parse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture),
double.Parse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture),
double.Parse(args[3], NumberStyles.Any, CultureInfo.CurrentCulture)
);
chunkX = pos.ChunkX;
chunkZ = pos.ChunkZ;
}
else if (args.Length == 1 + 2)
{
chunkX = int.Parse(args[1]);
chunkZ = int.Parse(args[2]);
chunkX = int.Parse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture);
chunkZ = int.Parse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture);
}
else
return null;

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using MinecraftClient.Inventory;
using MinecraftClient.Mapping;
@ -20,7 +21,7 @@ namespace MinecraftClient.Commands
{
try
{
int entityID = int.Parse(args[0]);
int entityID = int.Parse(args[0], NumberStyles.Any, CultureInfo.CurrentCulture);
if (entityID != 0)
{
if (handler.GetEntities().ContainsKey(entityID))

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using MinecraftClient.Inventory;
@ -24,14 +25,14 @@ namespace MinecraftClient.Commands
{
if (args.Length >= 4)
{
if (!int.TryParse(args[1], out int slot))
if (!int.TryParse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture, out int slot))
return GetCmdDescTranslated();
if (Enum.TryParse(args[2], true, out ItemType itemType))
{
if (handler.GetGamemode() == 1)
{
if (!int.TryParse(args[3], out int count))
if (!int.TryParse(args[3], NumberStyles.Any, CultureInfo.CurrentCulture, out int count))
return GetCmdDescTranslated();
if (handler.DoCreativeGive(slot, itemType, count, null))
@ -52,7 +53,7 @@ namespace MinecraftClient.Commands
{
if (args.Length >= 2)
{
if (!int.TryParse(args[1], out int slot))
if (!int.TryParse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture, out int slot))
return GetCmdDescTranslated();
if (handler.GetGamemode() == 1)
@ -105,7 +106,7 @@ namespace MinecraftClient.Commands
bool shouldUseItemCount = args.Length >= 3;
int itemCount = 0;
if (shouldUseItemCount && !int.TryParse(args[2], out itemCount))
if (shouldUseItemCount && !int.TryParse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture, out itemCount))
return GetCmdDescTranslated();
Dictionary<int, Container> inventories = handler.GetInventories();
@ -162,7 +163,7 @@ namespace MinecraftClient.Commands
else
return GetHelp();
}
else if (!int.TryParse(args[0], out inventoryId))
else if (!int.TryParse(args[0], NumberStyles.Any, CultureInfo.CurrentCulture, out inventoryId))
return GetCmdDescTranslated();
Container? inventory = handler.GetInventory(inventoryId);
@ -205,7 +206,7 @@ namespace MinecraftClient.Commands
}
else if (action == "click" && args.Length >= 3)
{
if (!int.TryParse(args[2], out int slot))
if (!int.TryParse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture, out int slot))
return GetCmdDescTranslated();
WindowActionType actionType = WindowActionType.LeftClick;
@ -224,7 +225,7 @@ namespace MinecraftClient.Commands
}
else if (action == "shiftclick" && args.Length >= 3)
{
if (!int.TryParse(args[2], out int slot))
if (!int.TryParse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture, out int slot))
return GetCmdDescTranslated();
if (!handler.DoWindowAction(inventoryId, slot, WindowActionType.ShiftClick))
@ -234,7 +235,7 @@ namespace MinecraftClient.Commands
}
else if (action == "drop" && args.Length >= 3)
{
if (!int.TryParse(args[2], out int slot))
if (!int.TryParse(args[2], NumberStyles.Any, CultureInfo.CurrentCulture, out int slot))
return GetCmdDescTranslated();
// check item exist

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using MinecraftClient.Mapping;
namespace MinecraftClient.Commands
@ -50,8 +51,8 @@ namespace MinecraftClient.Commands
{
try
{
float yaw = float.Parse(args[0]);
float pitch = float.Parse(args[1]);
float yaw = float.Parse(args[0], NumberStyles.Any, CultureInfo.CurrentCulture);
float pitch = float.Parse(args[1], NumberStyles.Any, CultureInfo.CurrentCulture);
handler.UpdateLocation(handler.GetCurrentLocation(), yaw, pitch);
return Translations.Get("cmd.look.at", yaw.ToString("0.00"), pitch.ToString("0.00"));

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Globalization;
namespace MinecraftClient.Inventory
{
@ -105,7 +106,7 @@ namespace MinecraftClient.Inventory
object damage = NBT["Damage"];
if (damage != null)
{
return int.Parse(damage.ToString() ?? string.Empty);
return int.Parse(damage.ToString() ?? string.Empty, NumberStyles.Any, CultureInfo.CurrentCulture);
}
}
return 0;

View file

@ -103,7 +103,8 @@ namespace MinecraftClient
&& IsHex(toparse[cursorpos + 5]))
{
//"abc\u0123abc" => "0123" => 0123 => Unicode char n°0123 => Add char to string
data.StringValue += char.ConvertFromUtf32(int.Parse(toparse.Substring(cursorpos + 2, 4), System.Globalization.NumberStyles.HexNumber));
data.StringValue += char.ConvertFromUtf32(int.Parse(toparse.Substring(cursorpos + 2, 4),
System.Globalization.NumberStyles.HexNumber));
cursorpos += 6; continue;
}
else if (toparse[cursorpos + 1] == 'n')

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
@ -66,7 +67,7 @@ namespace MinecraftClient.Mapping.BlockPalettes
foreach (Json.JSONData state in item.Value.Properties["states"].DataArray)
{
int id = int.Parse(state.Properties["id"].StringValue);
int id = int.Parse(state.Properties["id"].StringValue, NumberStyles.Any, CultureInfo.CurrentCulture);
if (knownStates.Contains(id))
throw new InvalidDataException("Duplicate state id " + id + "!?");

View file

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Runtime.CompilerServices;
namespace MinecraftClient.Mapping
@ -85,7 +86,7 @@ namespace MinecraftClient.Mapping
for (int i = 0; i < 3; ++i)
{
if (!double.TryParse(coord_str[i], out coord_res[i]))
if (!double.TryParse(coord_str[i], NumberStyles.Any, CultureInfo.CurrentCulture, out coord_res[i]))
{
location = null;
return false;
@ -126,7 +127,7 @@ namespace MinecraftClient.Mapping
{
if (coord_str[i].Length > 1)
{
if (!double.TryParse(coord_str[i][1..], out coord_res[i]))
if (!double.TryParse(coord_str[i][1..], NumberStyles.Any, CultureInfo.CurrentCulture, out coord_res[i]))
{
location = null;
return false;
@ -138,7 +139,7 @@ namespace MinecraftClient.Mapping
}
else
{
if (!double.TryParse(coord_str[i], out coord_res[i]))
if (!double.TryParse(coord_str[i], NumberStyles.Any, CultureInfo.CurrentCulture, out coord_res[i]))
{
location = null;
return false;

View file

@ -61,7 +61,6 @@ namespace MinecraftClient
private float playerPitch;
private double motionY;
public enum MovementType { Sneak, Walk, Sprint }
public int currentMovementSpeed = 4;
private int sequenceId; // User for player block synchronization (Aka. digging, placing blocks, etc..)
private readonly string host;
@ -337,7 +336,7 @@ namespace MinecraftClient
{
lock (locationLock)
{
for (int i = 0; i < currentMovementSpeed; i++) //Needs to run at 20 tps; MCC runs at 10 tps
for (int i = 0; i < Settings.MovementSpeed; i++) //Needs to run at 20 tps; MCC runs at 10 tps
{
if (_yaw == null || _pitch == null)
{
@ -2485,15 +2484,15 @@ namespace MinecraftClient
{
case MovementType.Sneak:
// https://minecraft.fandom.com/wiki/Sneaking#Effects - Sneaking 1.31m/s
currentMovementSpeed = 2;
Settings.MovementSpeed = 2;
break;
case MovementType.Walk:
// https://minecraft.fandom.com/wiki/Walking#Usage - Walking 4.317 m/s
currentMovementSpeed = 4;
Settings.MovementSpeed = 4;
break;
case MovementType.Sprint:
// https://minecraft.fandom.com/wiki/Sprinting#Usage - Sprinting 5.612 m/s
currentMovementSpeed = 5;
Settings.MovementSpeed = 5;
break;
}
}

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
@ -411,7 +412,7 @@ namespace MinecraftClient
return;
}
string worldId = addressInput.Split(':')[1];
if (!availableWorlds.Contains(worldId) && int.TryParse(worldId, out int worldIndex) && worldIndex < availableWorlds.Count)
if (!availableWorlds.Contains(worldId) && int.TryParse(worldId, NumberStyles.Any, CultureInfo.CurrentCulture, out int worldIndex) && worldIndex < availableWorlds.Count)
worldId = availableWorlds[worldIndex];
if (availableWorlds.Contains(worldId))
{

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
@ -26,7 +27,7 @@ namespace MinecraftClient.Protocol
foreach (KeyValuePair<string, Json.JSONData> entry in rawRegistry.Properties)
{
int entryId = int.Parse(entry.Value.Properties["protocol_id"].StringValue);
int entryId = int.Parse(entry.Value.Properties["protocol_id"].StringValue, NumberStyles.Any, CultureInfo.CurrentCulture);
//minecraft:item_name => ItemName
string entryName = String.Concat(

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Sockets;
using System.Security.Cryptography;
@ -872,7 +873,7 @@ namespace MinecraftClient.Protocol.Handlers
if (result.Length > 2 && result[0] == '§' && result[1] == '1')
{
string[] tmp = result.Split((char)0x00);
protocolversion = (byte)Int16.Parse(tmp[1]);
protocolversion = (byte)Int16.Parse(tmp[1], NumberStyles.Any, CultureInfo.CurrentCulture);
version = tmp[2];
if (protocolversion == 127) //MC 1.7.2+

View file

@ -2,6 +2,7 @@ using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Net.Sockets;
using System.Security.Cryptography;
@ -815,7 +816,7 @@ namespace MinecraftClient.Protocol.Handlers
List<MapIcon> icons = new();
// 1,9 + = needs tracking position to be true to get the icons
if (protocolVersion <= MC_1_9_Version || trackingPosition)
if (protocolVersion <= MC_1_16_5_Version || trackingPosition)
{
iconcount = dataTypes.ReadNextVarInt(packetData);
@ -2139,7 +2140,7 @@ namespace MinecraftClient.Protocol.Handlers
//Retrieve protocol version number for handling this server
if (versionData.Properties.ContainsKey("protocol"))
protocolVersion = int.Parse(versionData.Properties["protocol"].StringValue);
protocolVersion = int.Parse(versionData.Properties["protocol"].StringValue, NumberStyles.Any, CultureInfo.CurrentCulture);
// Check for forge on the server.
Protocol18Forge.ServerInfoCheckForge(jsonData, ref forgeInfo);

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
@ -73,7 +74,7 @@ namespace MinecraftClient.Protocol
{
string accessToken = jsonData.Properties["access_token"].StringValue;
string refreshToken = jsonData.Properties["refresh_token"].StringValue;
int expiresIn = int.Parse(jsonData.Properties["expires_in"].StringValue);
int expiresIn = int.Parse(jsonData.Properties["expires_in"].StringValue, NumberStyles.Any, CultureInfo.CurrentCulture);
// Extract email from JWT
string payload = JwtPayloadDecode.GetPayload(jsonData.Properties["id_token"].StringValue);
@ -237,7 +238,7 @@ namespace MinecraftClient.Protocol
Email = email,
AccessToken = dict["access_token"],
RefreshToken = dict["refresh_token"],
ExpiresIn = int.Parse(dict["expires_in"])
ExpiresIn = int.Parse(dict["expires_in"], NumberStyles.Any, CultureInfo.CurrentCulture)
};
}
else

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.Security;
using System.Net.Sockets;
@ -317,7 +318,7 @@ namespace MinecraftClient.Protocol
{
try
{
return Int32.Parse(MCVersion);
return Int32.Parse(MCVersion, NumberStyles.Any, CultureInfo.CurrentCulture);
}
catch
{
@ -628,7 +629,7 @@ namespace MinecraftClient.Protocol
{
var payload = JwtPayloadDecode.GetPayload(session.ID);
var json = Json.ParseJson(payload);
var expTimestamp = long.Parse(json.Properties["exp"].StringValue);
var expTimestamp = long.Parse(json.Properties["exp"].StringValue, NumberStyles.Any, CultureInfo.CurrentCulture);
var now = DateTime.Now;
var tokenExp = UnixTimeStampToDateTime(expTimestamp);
if (Settings.DebugMessages)

View file

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Net.Security;
using System.Net.Sockets;
@ -162,7 +163,7 @@ namespace MinecraftClient.Protocol
if (raw.StartsWith("HTTP/1.1") || raw.StartsWith("HTTP/1.0"))
{
Queue<string> msg = new(raw.Split(new string[] { "\r\n" }, StringSplitOptions.None));
statusCode = int.Parse(msg.Dequeue().Split(' ')[1]);
statusCode = int.Parse(msg.Dequeue().Split(' ')[1], NumberStyles.Any, CultureInfo.CurrentCulture);
while (msg.Peek() != "")
{

View file

@ -49,6 +49,7 @@ minecraftrealms=false # Enable support for joining Minecraft Realms
moveheadwhilewalking=true # Enable head movement while walking to avoid anti-cheat triggers
timeout=30 # Set a custom timeout in seconds (Default: 30). Use only if you know what you're doing.
enableemoji=true # If turned off, the emoji will be replaced with a simpler character (for /chunk status)
movementspeed=2 # A movement speed higher than 2 may be considered cheating.
[Signature]
# Chat settings (affects minecraft 1.19+)

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
@ -109,6 +110,7 @@ namespace MinecraftClient
public static bool MoveHeadWhileWalking = true;
public static int Timeout = 30;
public static bool EnableEmoji = true;
public static int MovementSpeed = 2;
// Signature
public static bool LoginWithSecureProfile = true;
@ -425,6 +427,7 @@ namespace MinecraftClient
case "moveheadwhilewalking": MoveHeadWhileWalking = str2bool(argValue); return true;
case "timeout": Timeout = str2int(argValue); return true;
case "enableemoji": EnableEmoji = str2bool(argValue); return true;
case "movementspwwd": MovementSpeed = str2int(argValue); return true;
case "botowners":
Bots_Owners.Clear();
@ -954,7 +957,7 @@ namespace MinecraftClient
/// <returns>Float number</returns>
public static float str2float(string str)
{
if (float.TryParse(str.Trim(), out float num))
if (float.TryParse(str.Trim(), NumberStyles.Any, CultureInfo.CurrentCulture, out float num))
return num;
else
{
@ -970,7 +973,7 @@ namespace MinecraftClient
/// <returns>Double number</returns>
public static double str2double(string str)
{
if (double.TryParse(str.Trim(), out double num))
if (double.TryParse(str.Trim(), NumberStyles.Any, CultureInfo.CurrentCulture, out double num))
return num;
else
{
@ -1016,7 +1019,7 @@ namespace MinecraftClient
for (int j = 0; j < curCodLen; ++j)
{
if (!double.TryParse(coordinates_str_list[j], out res![i, j]))
if (!double.TryParse(coordinates_str_list[j], NumberStyles.Any, CultureInfo.CurrentCulture, out res![i, j]))
{
ConsoleIO.WriteLogLine(Translations.Get("error.setting.str2locationList.convert_fail", coordinates_str_list[j]));
return null;

View file

@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System.Globalization;
using System.Runtime.InteropServices;
using Microsoft.Win32;
namespace MinecraftClient.WinAPI
@ -35,7 +36,7 @@ namespace MinecraftClient.WinAPI
var versionParts = ((string)version!).Split('.');
if (versionParts.Length != 2) return 0;
return uint.TryParse(versionParts[0], out uint majorAsUInt) ? majorAsUInt : 0;
return uint.TryParse(versionParts[0], NumberStyles.Any, CultureInfo.CurrentCulture, out uint majorAsUInt) ? majorAsUInt : 0;
}
return 0;
@ -62,7 +63,7 @@ namespace MinecraftClient.WinAPI
var versionParts = ((string)version!).Split('.');
if (versionParts.Length != 2) return 0;
return uint.TryParse(versionParts[1], out uint minorAsUInt) ? minorAsUInt : 0;
return uint.TryParse(versionParts[1], NumberStyles.Any, CultureInfo.CurrentCulture, out uint minorAsUInt) ? minorAsUInt : 0;
}
return 0;