diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index dfe07704..00000000 --- a/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -# Auto detect text files and perform LF normalization -* text=auto diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs index 9912d308..3b8c36fa 100644 --- a/MinecraftClient/Protocol/Handlers/DataTypes.cs +++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs @@ -324,16 +324,18 @@ namespace MinecraftClient.Protocol.Handlers /// private Dictionary ReadNextNbt(List cache, bool root) { + Dictionary NbtData = new Dictionary(); + if (root) { + if (cache[0] == 0) // TAG_End + return NbtData; if (cache[0] != 10) // TAG_Compound throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound"); ReadNextByte(cache); // Tag type (TAG_Compound) ReadData(ReadNextUShort(cache), cache); // NBT root name } - Dictionary NbtData = new Dictionary(); - while (true) { int fieldType = ReadNextByte(cache); @@ -445,7 +447,7 @@ namespace MinecraftClient.Protocol.Handlers if (protocolversion < Protocol18Handler.MC18Version) { byte[] length = BitConverter.GetBytes((short)array.Length); - Array.Reverse(length); + Array.Reverse(length); //Endianness return ConcatBytes(length, array); } else return ConcatBytes(GetVarInt(array.Length), array); @@ -464,7 +466,7 @@ namespace MinecraftClient.Protocol.Handlers } /// - /// 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 /// /// /// A modulo will be applied if the location is outside the following ranges: @@ -475,11 +477,14 @@ namespace MinecraftClient.Protocol.Handlers /// Location representation as ulong public byte[] GetLocation(Location location) { + byte[] locationBytes; 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; } /// diff --git a/MinecraftClient/config/sample-script-with-http-request.cs b/MinecraftClient/config/sample-script-with-http-request.cs new file mode 100644 index 00000000..5e4fba1e --- /dev/null +++ b/MinecraftClient/config/sample-script-with-http-request.cs @@ -0,0 +1,17 @@ +//MCCScript 1.0 + +string mojangStatus = PerformHttpRequest("https://status.mojang.com/check"); +MCC.LogToConsole(mojangStatus); + +//MCCScript Extensions + +string PerformHttpRequest(string uri) +{ + var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri); + var response = (System.Net.HttpWebResponse)request.GetResponse(); + string responseString; + using (var stream = response.GetResponseStream()) + using (var reader = new StreamReader(stream)) + responseString = reader.ReadToEnd(); + return responseString; +} \ No newline at end of file