Skip to content
This repository was archived by the owner on Apr 2, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ public void serialize(ByteBuf buffer, BedrockCodecHelper helper, PlayerAuthInput
buffer.writeFloatLE(packet.getMotion().getX());
buffer.writeFloatLE(packet.getMotion().getY());
buffer.writeFloatLE(rotation.getZ());
helper.writeLargeVarIntFlags(buffer, packet.getInputData(), PlayerAuthInputData.class);
long flagValue = 0;
for (PlayerAuthInputData data : packet.getInputData()) {
flagValue |= (1L << data.ordinal());
}
VarInts.writeUnsignedLong(buffer, flagValue);
VarInts.writeUnsignedInt(buffer, packet.getInputMode().ordinal());
VarInts.writeUnsignedInt(buffer, packet.getPlayMode().ordinal());
writeInteractionModel(buffer, helper, packet);
Expand Down Expand Up @@ -60,7 +64,12 @@ public void deserialize(ByteBuf buffer, BedrockCodecHelper helper, PlayerAuthInp
packet.setMotion(Vector2f.from(buffer.readFloatLE(), buffer.readFloatLE()));
float z = buffer.readFloatLE();
packet.setRotation(Vector3f.from(x, y, z));
helper.readLargeVarIntFlags(buffer, packet.getInputData(), PlayerAuthInputData.class);
long flagValue = VarInts.readUnsignedLong(buffer);
for (PlayerAuthInputData flag : PlayerAuthInputData.values()) {
if ((flagValue & (1L << flag.ordinal())) != 0) {
packet.getInputData().add(flag);
}
}
packet.setInputMode(INPUT_MODES[VarInts.readUnsignedInt(buffer)]);
packet.setPlayMode(CLIENT_PLAY_MODES[VarInts.readUnsignedInt(buffer)]);
readInteractionModel(buffer, helper, packet);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package org.allaymc.protocol.extension.codec.v686;

import io.netty.buffer.ByteBuf;
import org.cloudburstmc.protocol.bedrock.codec.EntityDataTypeMap;
import org.cloudburstmc.protocol.bedrock.codec.v575.BedrockCodecHelper_v575;
import org.cloudburstmc.protocol.bedrock.data.Ability;
import org.cloudburstmc.protocol.bedrock.data.PlayerAuthInputData;
import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType;
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.TextProcessingEventOrigin;
import org.cloudburstmc.protocol.bedrock.data.inventory.itemstack.request.action.ItemStackRequestActionType;
import org.cloudburstmc.protocol.common.util.TypeMap;
import org.cloudburstmc.protocol.common.util.VarInts;

import java.math.BigInteger;
import java.util.Set;

/**
* NetEase variant of the v686 codec helper.
* Implements readLargeVarIntFlags/writeLargeVarIntFlags with NetEase flag offset adaptation (neteaseFlags1212).
*
* @author LT_Name
*/
public class BedrockCodecHelper_v686_NetEase extends BedrockCodecHelper_v575 {

// NetEase inserts an extra flag at this position (after RECEIVED_SERVER_DATA)
private static final int PLAYER_AUTH_INPUT_DATA_NETEASE = PlayerAuthInputData.RECEIVED_SERVER_DATA.ordinal() + 1;

public BedrockCodecHelper_v686_NetEase(EntityDataTypeMap entityData, TypeMap<Class<?>> gameRulesTypes, TypeMap<ItemStackRequestActionType> stackRequestActionTypes, TypeMap<ContainerSlotType> containerSlotTypes, TypeMap<Ability> abilities, TypeMap<TextProcessingEventOrigin> textProcessingEventOrigins) {
super(entityData, gameRulesTypes, stackRequestActionTypes, containerSlotTypes, abilities, textProcessingEventOrigins);
}

@Override
public <T extends Enum<?>> void readLargeVarIntFlags(ByteBuf buffer, Set<T> flags, Class<T> clazz) {
var needNetEaseAdaptation = clazz == PlayerAuthInputData.class;
BigInteger flagsInt = VarInts.readUnsignedBigVarInt(buffer, clazz.getEnumConstants().length);
for (T flag : clazz.getEnumConstants()) {
var ordinal = flag.ordinal();
if (needNetEaseAdaptation) {
if (ordinal == PLAYER_AUTH_INPUT_DATA_NETEASE) {
// Ignore PlayerAuthInputData.NETEASE
continue;
}

if (ordinal > PLAYER_AUTH_INPUT_DATA_NETEASE) {
ordinal -= 1;
}
}
if (flagsInt.testBit(ordinal)) {
flags.add(flag);
}
}
}

@Override
public <T extends Enum<?>> void writeLargeVarIntFlags(ByteBuf buffer, Set<T> flags, Class<T> clazz) {
var needNetEaseAdaptation = clazz == PlayerAuthInputData.class;
BigInteger flagsInt = BigInteger.ZERO;
for (T flag : flags) {
var ordinal = flag.ordinal();
if (needNetEaseAdaptation && ordinal >= PLAYER_AUTH_INPUT_DATA_NETEASE) {
ordinal += 1;
}
flagsInt = flagsInt.setBit(ordinal);
}
VarInts.writeUnsignedBigVarInt(buffer, flagsInt);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.allaymc.protocol.extension.packet.StoreBuySuccessPacket;
import org.allaymc.protocol.extension.codec.common.serializer.PlayerEnchantOptionsSerializer_v407_NetEase;
import org.cloudburstmc.protocol.bedrock.codec.BedrockCodec;
import org.cloudburstmc.protocol.bedrock.codec.v575.BedrockCodecHelper_v575;
import org.cloudburstmc.protocol.bedrock.codec.v686.Bedrock_v686;
import org.cloudburstmc.protocol.bedrock.data.PacketRecipient;
import org.cloudburstmc.protocol.bedrock.data.inventory.ContainerSlotType;
Expand All @@ -36,7 +35,7 @@ public class Bedrock_v686_NetEase extends Bedrock_v686 {

public static final BedrockCodec CODEC = Bedrock_v686.CODEC.toBuilder()
.raknetProtocolVersion(8)
.helper(() -> new BedrockCodecHelper_v575(ENTITY_DATA, GAME_RULE_TYPES, ITEM_STACK_REQUEST_TYPES, CONTAINER_SLOT_TYPES, PLAYER_ABILITIES, TEXT_PROCESSING_ORIGINS))
.helper(() -> new BedrockCodecHelper_v686_NetEase(ENTITY_DATA, GAME_RULE_TYPES, ITEM_STACK_REQUEST_TYPES, CONTAINER_SLOT_TYPES, PLAYER_ABILITIES, TEXT_PROCESSING_ORIGINS))
.updateSerializer(PlayerAuthInputPacket.class, PlayerAuthInputSerializer_v686_NetEase.INSTANCE)
.updateSerializer(TextPacket.class, TextSerializer_v686_NetEase.INSTANCE)
.updateSerializer(PlayerEnchantOptionsPacket.class, PlayerEnchantOptionsSerializer_v407_NetEase.INSTANCE)
Expand Down