Skip to content

Decode PerformVoxelActions#1

Open
MichalSy wants to merge 5 commits into
EDITzDev:mainfrom
MichalSy:feature/add-PerformVoxelActions
Open

Decode PerformVoxelActions#1
MichalSy wants to merge 5 commits into
EDITzDev:mainfrom
MichalSy:feature/add-PerformVoxelActions

Conversation

@MichalSy

Copy link
Copy Markdown

No description provided.

@EDITzDev

Copy link
Copy Markdown
Owner

Thanks for the PR!
You're on the right track but the packet structure is slightly different. I've actually reversed this packet but haven't committed the changes yet.

Here is the structure;

Name Offset Bits
location 0 4
chunkCoordX 4 6
chunkCoordY 10 6
chunkCoordZ 16 6
voxelCoordX 22 6
voxelCoordY 28 6
voxelCoordZ 34 6
side 40 3
power 43 6
positionX 49 17
positionY 66 17
positionZ 83 17
directionX 100 8
directionY 108 8
directionZ 116 8

Here is how I've read the data;

public static bool Handle(Connection connection, BitStream bitStream)
{
    var inOutByteArray = new byte[4];

    if (!bitStream.ReadBits(inOutByteArray, 8 - Util.NumBitsRequiredByte(8), true))
        return false;

    var location = inOutByteArray[0];

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(32), true))
        return false;

    var chunkCoordX = BitConverter.ToInt32(inOutByteArray, 0);

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(32), true))
        return false;

    var chunkCoordY = BitConverter.ToInt32(inOutByteArray, 0);

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(32), true))
        return false;

    var chunkCoordZ = BitConverter.ToInt32(inOutByteArray, 0);

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(32), true))
        return false;

    var voxelCoordX = BitConverter.ToInt32(inOutByteArray, 0);

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(32), true))
        return false;

    var voxelCoordY = BitConverter.ToInt32(inOutByteArray, 0);

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(32), true))
        return false;

    var voxelCoordZ = BitConverter.ToInt32(inOutByteArray, 0);

    if (!bitStream.ReadBits(inOutByteArray, 8 - Util.NumBitsRequiredByte(6), true))
        return false;

    var side = inOutByteArray[0];

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(32), true))
        return false;

    var power = BitConverter.ToInt32(inOutByteArray, 0);

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(0x10000), true))
        return false;

    var positionX = BitConverter.ToInt32(inOutByteArray, 0);

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(0x10000), true))
        return false;

    var positionY = BitConverter.ToInt32(inOutByteArray, 0);

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(0x10000), true))
        return false;

    var positionZ = BitConverter.ToInt32(inOutByteArray, 0);

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(128), true))
        return false;

    var directionX = BitConverter.ToInt32(inOutByteArray, 0);

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(128), true))
        return false;

    var directionY = BitConverter.ToInt32(inOutByteArray, 0);

    if (!bitStream.ReadBits(inOutByteArray, 32 - Util.NumBitsRequiredUInt32(128), true))
        return false;

    var directionZ = BitConverter.ToInt32(inOutByteArray, 0);

    Debug.WriteLine($"location: {location}, chunkCoord: {chunkCoordX} {chunkCoordY} {chunkCoordZ}, voxelCoord: {voxelCoordX} {voxelCoordY} {voxelCoordZ}, side: {side}, power: {power}, position: {positionX} {positionY} {positionZ}, direction: {directionX} {directionY} {directionZ}", nameof(PerformVoxelActions));

    return true;
}

Comment thread Servers/SkySaga.Game/Extensions/ByteArrayExtensions.cs Outdated
Comment on lines +55 to +57
var bitsToSkip = 8 - Util.NumBitsRequiredByte(maxValue);

if (!bitStream.ReadBits(buffer, bitsToSkip, alignBitsToRight: true))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bitsToSkip should be named something like bitsToRead

Comment thread Servers/SkySaga.Game/Extensions/BitStreamExtensions.cs Outdated
Comment thread Servers/SkySaga.Game/Packets/PerformVoxelActions.cs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants