From 787a6a2a5a09b31e98dfdec98b6b541a314fae6f Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Mon, 10 Apr 2017 16:49:07 +1000 Subject: [PATCH] Initial work on larger player positions --- ClassicalSharp/Network/CPESupport.cs | 10 +++++++--- ClassicalSharp/Network/NetworkProcessor.Helpers.cs | 2 +- ClassicalSharp/Network/Protocols/Classic.cs | 12 +++--------- ClassicalSharp/Network/Utils/NetReader.cs | 10 ++++++++++ ClassicalSharp/Network/Utils/NetWriter.cs | 7 +++++++ 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/ClassicalSharp/Network/CPESupport.cs b/ClassicalSharp/Network/CPESupport.cs index ddb609b7e..142e43fd0 100644 --- a/ClassicalSharp/Network/CPESupport.cs +++ b/ClassicalSharp/Network/CPESupport.cs @@ -14,13 +14,14 @@ namespace ClassicalSharp.Network { internal int ServerExtensionsCount; internal bool sendHeldBlock, useMessageTypes; internal int envMapVer = 2, blockDefsExtVer = 2; - internal bool needD3Fix; + internal bool needD3Fix, extEntityPos; public void Reset(Game game) { ServerExtensionsCount = 0; sendHeldBlock = false; useMessageTypes = false; envMapVer = 2; blockDefsExtVer = 2; - needD3Fix = false; game.UseCPEBlocks = false; + needD3Fix = false; extEntityPos = false; + game.UseCPEBlocks = false; NetworkProcessor net = (NetworkProcessor)game.Server; net.Reset(); @@ -51,6 +52,9 @@ namespace ClassicalSharp.Network { blockDefsExtVer = version; if (version == 1) return; net.packetSizes[(byte)Opcode.CpeDefineBlockExt] = 88; + } else if (ext == "ExtEntityPositions") { + //extEntityPos = true; + // TODO: need to increase packet sizes accordingly } } @@ -59,7 +63,7 @@ namespace ClassicalSharp.Network { "EnvColors", "SelectionCuboid", "BlockPermissions", "ChangeModel", "EnvMapAppearance", "EnvWeatherType", "HackControl", "MessageTypes", "PlayerClick", "FullCP437", "LongerMessages", "BlockDefinitions", "BlockDefinitionsExt", "BulkBlockUpdate", "TextColors", - "EnvMapAspect", "EntityProperty", + "EnvMapAspect", "EntityProperty", "ExtEntityPositions", }; } } diff --git a/ClassicalSharp/Network/NetworkProcessor.Helpers.cs b/ClassicalSharp/Network/NetworkProcessor.Helpers.cs index 7455d1545..31a6da425 100644 --- a/ClassicalSharp/Network/NetworkProcessor.Helpers.cs +++ b/ClassicalSharp/Network/NetworkProcessor.Helpers.cs @@ -53,7 +53,7 @@ namespace ClassicalSharp.Network { game.LocalPlayer.UpdateName(); } - if (!readPosition) return; + if (!readPosition) return; classic.ReadAbsoluteLocation(id, false); if (id != EntityList.SelfID) return; diff --git a/ClassicalSharp/Network/Protocols/Classic.cs b/ClassicalSharp/Network/Protocols/Classic.cs index a2d692737..f757f8d7e 100644 --- a/ClassicalSharp/Network/Protocols/Classic.cs +++ b/ClassicalSharp/Network/Protocols/Classic.cs @@ -257,16 +257,12 @@ namespace ClassicalSharp.Network.Protocols { } internal void ReadAbsoluteLocation(byte id, bool interpolate) { - float x = reader.ReadInt16() / 32f; - float y = (reader.ReadInt16() - 51) / 32f; // We have to do this. - if (id == EntityList.SelfID) y += 22/32f; - float z = reader.ReadInt16() / 32f; - + Vector3 P = reader.ReadPosition(id); float rotY = (float)Utils.PackedToDegrees(reader.ReadUInt8()); float headX = (float)Utils.PackedToDegrees(reader.ReadUInt8()); if (id == EntityList.SelfID) net.receivedFirstPosition = true; - LocationUpdate update = LocationUpdate.MakePosAndOri(x, y, z, rotY, headX, false); + LocationUpdate update = LocationUpdate.MakePosAndOri(P, rotY, headX, false); net.UpdateLocation(id, update, interpolate); } #endregion @@ -287,9 +283,7 @@ namespace ClassicalSharp.Network.Protocols { writer.WriteUInt8((byte)Opcode.EntityTeleport); writer.WriteUInt8((byte)payload); // held block when using HeldBlock, otherwise just 255 - writer.WriteInt16((short)(pos.X * 32)); - writer.WriteInt16((short)((int)(pos.Y * 32) + 51)); - writer.WriteInt16((short)(pos.Z * 32)); + writer.WritePosition(pos); writer.WriteUInt8((byte)Utils.DegreesToPacked(rotY)); writer.WriteUInt8((byte)Utils.DegreesToPacked(headX)); net.SendPacket(); diff --git a/ClassicalSharp/Network/Utils/NetReader.cs b/ClassicalSharp/Network/Utils/NetReader.cs index 72cf1b1e9..96005da9b 100644 --- a/ClassicalSharp/Network/Utils/NetReader.cs +++ b/ClassicalSharp/Network/Utils/NetReader.cs @@ -1,6 +1,8 @@ // Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 using System; using System.Net.Sockets; +using ClassicalSharp.Entities; +using OpenTK; namespace ClassicalSharp.Network { @@ -71,6 +73,14 @@ namespace ClassicalSharp.Network { index += length; return data; } + + public Vector3 ReadPosition(byte id) { + float x = ReadInt16() / 32f; + float y = (ReadInt16() - 51) / 32f; // We have to do this. + if (id == EntityList.SelfID) y += 22/32f; + float z = ReadInt16() / 32f; + return new Vector3(x, y, z); + } public string ReadString() { int length = GetString(Utils.StringLength); diff --git a/ClassicalSharp/Network/Utils/NetWriter.cs b/ClassicalSharp/Network/Utils/NetWriter.cs index b2371200c..dbe51954c 100644 --- a/ClassicalSharp/Network/Utils/NetWriter.cs +++ b/ClassicalSharp/Network/Utils/NetWriter.cs @@ -1,6 +1,7 @@ // Copyright 2014-2017 ClassicalSharp | Licensed under BSD-3 using System; using System.Net.Sockets; +using OpenTK; namespace ClassicalSharp.Network { @@ -37,6 +38,12 @@ namespace ClassicalSharp.Network { index += Utils.StringLength; } + public void WritePosition(Vector3 pos) { + WriteInt16((short)(pos.X * 32)); + WriteInt16((short)((int)(pos.Y * 32) + 51)); + WriteInt16((short)(pos.Z * 32)); + } + public void WriteUInt8(byte value) { buffer[index++] = value; }