Fix GetLocation() endianness (#881)

This commit is contained in:
ORelio 2020-03-05 21:38:07 +01:00
parent 2e52bdea39
commit 981bae184a

View file

@ -445,7 +445,7 @@ namespace MinecraftClient.Protocol.Handlers
if (protocolversion < Protocol18Handler.MC18Version) if (protocolversion < Protocol18Handler.MC18Version)
{ {
byte[] length = BitConverter.GetBytes((short)array.Length); byte[] length = BitConverter.GetBytes((short)array.Length);
Array.Reverse(length); Array.Reverse(length); //Endianness
return ConcatBytes(length, array); return ConcatBytes(length, array);
} }
else return ConcatBytes(GetVarInt(array.Length), array); else return ConcatBytes(GetVarInt(array.Length), array);
@ -464,7 +464,7 @@ namespace MinecraftClient.Protocol.Handlers
} }
/// <summary> /// <summary>
/// Get a byte array representing the given location encoded as an unsigned short /// Get a byte array representing the given location encoded as an unsigned long
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// A modulo will be applied if the location is outside the following ranges: /// A modulo will be applied if the location is outside the following ranges:
@ -475,11 +475,14 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns>Location representation as ulong</returns> /// <returns>Location representation as ulong</returns>
public byte[] GetLocation(Location location) public byte[] GetLocation(Location location)
{ {
byte[] locationBytes;
if (protocolversion >= Protocol18Handler.MC114Version) if (protocolversion >= Protocol18Handler.MC114Version)
{ {
return BitConverter.GetBytes(((((ulong)location.X) & 0x3FFFFFF) << 38) | ((((ulong)location.Z) & 0x3FFFFFF) << 12) | (((ulong)location.Y) & 0xFFF)); locationBytes = BitConverter.GetBytes(((((ulong)location.X) & 0x3FFFFFF) << 38) | ((((ulong)location.Z) & 0x3FFFFFF) << 12) | (((ulong)location.Y) & 0xFFF));
} }
else return BitConverter.GetBytes(((((ulong)location.X) & 0x3FFFFFF) << 38) | ((((ulong)location.Y) & 0xFFF) << 26) | (((ulong)location.Z) & 0x3FFFFFF)); else locationBytes = BitConverter.GetBytes(((((ulong)location.X) & 0x3FFFFFF) << 38) | ((((ulong)location.Y) & 0xFFF) << 26) | (((ulong)location.Z) & 0x3FFFFFF));
Array.Reverse(locationBytes); //Endianness
return locationBytes;
} }
/// <summary> /// <summary>