Skip to content

Commit

Permalink
Protocol changes for 1.21.50 (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c authored Dec 4, 2024
1 parent 84d89be commit bd1ec79
Show file tree
Hide file tree
Showing 23 changed files with 842 additions and 42 deletions.
8 changes: 7 additions & 1 deletion src/CameraAimAssistPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
class CameraAimAssistPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::CAMERA_AIM_ASSIST_PACKET;

private string $presetId;
private Vector2 $viewAngle;
private float $distance;
private CameraAimAssistTargetMode $targetMode;
Expand All @@ -30,15 +31,18 @@ class CameraAimAssistPacket extends DataPacket implements ClientboundPacket{
/**
* @generate-create-func
*/
public static function create(Vector2 $viewAngle, float $distance, CameraAimAssistTargetMode $targetMode, CameraAimAssistActionType $actionType) : self{
public static function create(string $presetId, Vector2 $viewAngle, float $distance, CameraAimAssistTargetMode $targetMode, CameraAimAssistActionType $actionType) : self{
$result = new self;
$result->presetId = $presetId;
$result->viewAngle = $viewAngle;
$result->distance = $distance;
$result->targetMode = $targetMode;
$result->actionType = $actionType;
return $result;
}

public function getPresetId() : string{ return $this->presetId; }

public function getViewAngle() : Vector2{ return $this->viewAngle; }

public function getDistance() : float{ return $this->distance; }
Expand All @@ -48,13 +52,15 @@ public function getTargetMode() : CameraAimAssistTargetMode{ return $this->targe
public function getActionType() : CameraAimAssistActionType{ return $this->actionType; }

protected function decodePayload(PacketSerializer $in) : void{
$this->presetId = $in->getString();
$this->viewAngle = $in->getVector2();
$this->distance = $in->getLFloat();
$this->targetMode = CameraAimAssistTargetMode::fromPacket($in->getByte());
$this->actionType = CameraAimAssistActionType::fromPacket($in->getByte());
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putString($this->presetId);
$out->putVector2($this->viewAngle);
$out->putLFloat($this->distance);
$out->putByte($this->targetMode->value);
Expand Down
79 changes: 79 additions & 0 deletions src/CameraAimAssistPresetsPacket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<?php

/*
* This file is part of BedrockProtocol.
* Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
*
* BedrockProtocol is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*/

declare(strict_types=1);

namespace pocketmine\network\mcpe\protocol;

use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\camera\CameraAimAssistCategories;
use pocketmine\network\mcpe\protocol\types\camera\CameraAimAssistPreset;
use function count;

class CameraAimAssistPresetsPacket extends DataPacket implements ClientboundPacket{
public const NETWORK_ID = ProtocolInfo::CAMERA_AIM_ASSIST_PRESETS_PACKET;

/** @var CameraAimAssistCategories[] */
private array $categories;
/** @var CameraAimAssistPreset[] */
private array $presets;

/**
* @generate-create-func
* @param CameraAimAssistCategories[] $categories
* @param CameraAimAssistPreset[] $presets
*/
public static function create(array $categories, array $presets) : self{
$result = new self;
$result->categories = $categories;
$result->presets = $presets;
return $result;
}

/**
* @return CameraAimAssistCategories[]
*/
public function getCategories() : array{ return $this->categories; }

/**
* @return CameraAimAssistPreset[]
*/
public function getPresets() : array{ return $this->presets; }

protected function decodePayload(PacketSerializer $in) : void{
$this->categories = [];
for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
$this->categories[] = CameraAimAssistCategories::read($in);
}

$this->presets = [];
for($i = 0, $count = $in->getUnsignedVarInt(); $i < $count; ++$i){
$this->presets[] = CameraAimAssistPreset::read($in);
}
}

protected function encodePayload(PacketSerializer $out) : void{
$out->putUnsignedVarInt(count($this->categories));
foreach($this->categories as $category){
$category->write($out);
}

$out->putUnsignedVarInt(count($this->presets));
foreach($this->presets as $preset){
$preset->write($out);
}
}

public function handle(PacketHandlerInterface $handler) : bool{
return $handler->handleCameraAimAssistPresets($this);
}
}
4 changes: 4 additions & 0 deletions src/PacketHandlerDefaultImplTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -837,4 +837,8 @@ public function handleMovementEffect(MovementEffectPacket $packet) : bool{
public function handleSetMovementAuthority(SetMovementAuthorityPacket $packet) : bool{
return false;
}

public function handleCameraAimAssistPresets(CameraAimAssistPresetsPacket $packet) : bool{
return false;
}
}
2 changes: 2 additions & 0 deletions src/PacketHandlerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,4 +425,6 @@ public function handleContainerRegistryCleanup(ContainerRegistryCleanupPacket $p
public function handleMovementEffect(MovementEffectPacket $packet) : bool;

public function handleSetMovementAuthority(SetMovementAuthorityPacket $packet) : bool;

public function handleCameraAimAssistPresets(CameraAimAssistPresetsPacket $packet) : bool;
}
1 change: 1 addition & 0 deletions src/PacketPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public function __construct(){
$this->registerPacket(new ContainerRegistryCleanupPacket());
$this->registerPacket(new MovementEffectPacket());
$this->registerPacket(new SetMovementAuthorityPacket());
$this->registerPacket(new CameraAimAssistPresetsPacket());
}

public function registerPacket(Packet $packet) : void{
Expand Down
59 changes: 30 additions & 29 deletions src/PlayerAuthInputPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use pocketmine\math\Vector2;
use pocketmine\math\Vector3;
use pocketmine\network\mcpe\protocol\serializer\BitSet;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\types\InputMode;
use pocketmine\network\mcpe\protocol\types\InteractionMode;
Expand All @@ -38,7 +39,7 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
private float $headYaw;
private float $moveVecX;
private float $moveVecZ;
private int $inputFlags;
private BitSet $inputFlags;
private int $inputMode;
private int $playMode;
private int $interactionMode;
Expand All @@ -53,6 +54,7 @@ class PlayerAuthInputPacket extends DataPacket implements ServerboundPacket{
private float $analogMoveVecX;
private float $analogMoveVecZ;
private Vector3 $cameraOrientation;
private Vector2 $rawMove;

/**
* @generate-create-func
Expand All @@ -65,7 +67,7 @@ private static function internalCreate(
float $headYaw,
float $moveVecX,
float $moveVecZ,
int $inputFlags,
BitSet $inputFlags,
int $inputMode,
int $playMode,
int $interactionMode,
Expand All @@ -79,6 +81,7 @@ private static function internalCreate(
float $analogMoveVecX,
float $analogMoveVecZ,
Vector3 $cameraOrientation,
Vector2 $rawMove,
) : self{
$result = new self;
$result->position = $position;
Expand All @@ -101,11 +104,12 @@ private static function internalCreate(
$result->analogMoveVecX = $analogMoveVecX;
$result->analogMoveVecZ = $analogMoveVecZ;
$result->cameraOrientation = $cameraOrientation;
$result->rawMove = $rawMove;
return $result;
}

/**
* @param int $inputFlags @see PlayerAuthInputFlags
* @param BitSet $inputFlags @see PlayerAuthInputFlags
* @param int $inputMode @see InputMode
* @param int $playMode @see PlayMode
* @param int $interactionMode @see InteractionMode
Expand All @@ -118,7 +122,7 @@ public static function create(
float $headYaw,
float $moveVecX,
float $moveVecZ,
int $inputFlags,
BitSet $inputFlags,
int $inputMode,
int $playMode,
int $interactionMode,
Expand All @@ -131,30 +135,26 @@ public static function create(
?PlayerAuthInputVehicleInfo $vehicleInfo,
float $analogMoveVecX,
float $analogMoveVecZ,
Vector3 $cameraOrientation
Vector3 $cameraOrientation,
Vector2 $rawMove
) : self{
$realInputFlags = $inputFlags & ~((1 << PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST) | (1 << PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION) | (1 << PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS));
if($itemStackRequest !== null){
$realInputFlags |= 1 << PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST;
}
if($itemInteractionData !== null){
$realInputFlags |= 1 << PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION;
}
if($blockActions !== null){
$realInputFlags |= 1 << PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS;
}
if($vehicleInfo !== null){
$realInputFlags |= 1 << PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE;
if($inputFlags->getLength() !== 65){
throw new \InvalidArgumentException("Input flags must be 65 bits long");
}

$inputFlags->set(PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST, $itemStackRequest !== null);
$inputFlags->set(PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION, $itemInteractionData !== null);
$inputFlags->set(PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS, $blockActions !== null);
$inputFlags->set(PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE, $vehicleInfo !== null);

return self::internalCreate(
$position,
$pitch,
$yaw,
$headYaw,
$moveVecX,
$moveVecZ,
$realInputFlags,
$inputFlags,
$inputMode,
$playMode,
$interactionMode,
Expand All @@ -167,7 +167,8 @@ public static function create(
$vehicleInfo,
$analogMoveVecX,
$analogMoveVecZ,
$cameraOrientation
$cameraOrientation,
$rawMove
);
}

Expand Down Expand Up @@ -198,7 +199,7 @@ public function getMoveVecZ() : float{
/**
* @see PlayerAuthInputFlags
*/
public function getInputFlags() : int{
public function getInputFlags() : BitSet{
return $this->inputFlags;
}

Expand Down Expand Up @@ -256,9 +257,7 @@ public function getAnalogMoveVecZ() : float{ return $this->analogMoveVecZ; }

public function getCameraOrientation() : Vector3{ return $this->cameraOrientation; }

public function hasFlag(int $flag) : bool{
return ($this->inputFlags & (1 << $flag)) !== 0;
}
public function getRawMove() : Vector2{ return $this->rawMove; }

protected function decodePayload(PacketSerializer $in) : void{
$this->pitch = $in->getLFloat();
Expand All @@ -267,20 +266,20 @@ protected function decodePayload(PacketSerializer $in) : void{
$this->moveVecX = $in->getLFloat();
$this->moveVecZ = $in->getLFloat();
$this->headYaw = $in->getLFloat();
$this->inputFlags = $in->getUnsignedVarLong();
$this->inputFlags = BitSet::read($in, 65);
$this->inputMode = $in->getUnsignedVarInt();
$this->playMode = $in->getUnsignedVarInt();
$this->interactionMode = $in->getUnsignedVarInt();
$this->interactRotation = $in->getVector2();
$this->tick = $in->getUnsignedVarLong();
$this->delta = $in->getVector3();
if($this->hasFlag(PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION)){
if($this->inputFlags->get(PlayerAuthInputFlags::PERFORM_ITEM_INTERACTION)){
$this->itemInteractionData = ItemInteractionData::read($in);
}
if($this->hasFlag(PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST)){
if($this->inputFlags->get(PlayerAuthInputFlags::PERFORM_ITEM_STACK_REQUEST)){
$this->itemStackRequest = ItemStackRequest::read($in);
}
if($this->hasFlag(PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS)){
if($this->inputFlags->get(PlayerAuthInputFlags::PERFORM_BLOCK_ACTIONS)){
$this->blockActions = [];
$max = $in->getVarInt();
for($i = 0; $i < $max; ++$i){
Expand All @@ -292,12 +291,13 @@ protected function decodePayload(PacketSerializer $in) : void{
};
}
}
if($this->hasFlag(PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE)){
if($this->inputFlags->get(PlayerAuthInputFlags::IN_CLIENT_PREDICTED_VEHICLE)){
$this->vehicleInfo = PlayerAuthInputVehicleInfo::read($in);
}
$this->analogMoveVecX = $in->getLFloat();
$this->analogMoveVecZ = $in->getLFloat();
$this->cameraOrientation = $in->getVector3();
$this->rawMove = $in->getVector2();
}

protected function encodePayload(PacketSerializer $out) : void{
Expand All @@ -307,7 +307,7 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putLFloat($this->moveVecX);
$out->putLFloat($this->moveVecZ);
$out->putLFloat($this->headYaw);
$out->putUnsignedVarLong($this->inputFlags);
$this->inputFlags->write($out);
$out->putUnsignedVarInt($this->inputMode);
$out->putUnsignedVarInt($this->playMode);
$out->putUnsignedVarInt($this->interactionMode);
Expand All @@ -333,6 +333,7 @@ protected function encodePayload(PacketSerializer $out) : void{
$out->putLFloat($this->analogMoveVecX);
$out->putLFloat($this->analogMoveVecZ);
$out->putVector3($this->cameraOrientation);
$out->putVector2($this->rawMove);
}

public function handle(PacketHandlerInterface $handler) : bool{
Expand Down
7 changes: 4 additions & 3 deletions src/ProtocolInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ private function __construct(){
*/

/** Actual Minecraft: PE protocol version */
public const CURRENT_PROTOCOL = 748;
public const CURRENT_PROTOCOL = 766;
/** Current Minecraft PE version reported by the server. This is usually the earliest currently supported version. */
public const MINECRAFT_VERSION = 'v1.21.40';
public const MINECRAFT_VERSION = 'v1.21.50';
/** Version number sent to clients in ping responses. */
public const MINECRAFT_VERSION_NETWORK = '1.21.40';
public const MINECRAFT_VERSION_NETWORK = '1.21.50';

public const LOGIN_PACKET = 0x01;
public const PLAY_STATUS_PACKET = 0x02;
Expand Down Expand Up @@ -255,4 +255,5 @@ private function __construct(){
public const CONTAINER_REGISTRY_CLEANUP_PACKET = 0x13d;
public const MOVEMENT_EFFECT_PACKET = 0x13e;
public const SET_MOVEMENT_AUTHORITY_PACKET = 0x13f;
public const CAMERA_AIM_ASSIST_PRESETS_PACKET = 0x140;
}
Loading

0 comments on commit bd1ec79

Please sign in to comment.