Skip to content

Commit e47fd09

Browse files
committed
Fixes
1 parent aeabbc5 commit e47fd09

25 files changed

Lines changed: 829 additions & 98 deletions

src/ClientCacheBlobStatusPacket.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,31 @@ public function getMissHashes() : array{
5656

5757
protected function decodePayload(ByteBufferReader $in, int $protocolId) : void{
5858
$missCount = VarInt::readUnsignedInt($in);
59+
if($protocolId <= ProtocolInfo::PROTOCOL_1_26_20){
60+
$hitCount = VarInt::readUnsignedInt($in);
61+
}
5962
for($i = 0; $i < $missCount; ++$i){
6063
$this->missHashes[] = LE::readUnsignedLong($in);
6164
}
62-
$hitCount = VarInt::readUnsignedInt($in);
63-
for($i = 0; $i < $hitCount; ++$i){
65+
if($protocolId >= ProtocolInfo::PROTOCOL_1_26_30){
66+
$hitCount = VarInt::readUnsignedInt($in);
67+
}
68+
for($i = 0; $i < ($hitCount ?? 0); ++$i){
6469
$this->hitHashes[] = LE::readUnsignedLong($in);
6570
}
6671
}
6772

6873
protected function encodePayload(ByteBufferWriter $out, int $protocolId) : void{
6974
VarInt::writeUnsignedInt($out, count($this->missHashes));
75+
if($protocolId <= ProtocolInfo::PROTOCOL_1_26_20){
76+
VarInt::writeUnsignedInt($out, count($this->hitHashes));
77+
}
7078
foreach($this->missHashes as $hash){
7179
LE::writeUnsignedLong($out, $hash);
7280
}
73-
VarInt::writeUnsignedInt($out, count($this->hitHashes));
81+
if($protocolId >= ProtocolInfo::PROTOCOL_1_26_30){
82+
VarInt::writeUnsignedInt($out, count($this->hitHashes));
83+
}
7484
foreach($this->hitHashes as $hash){
7585
LE::writeUnsignedLong($out, $hash);
7686
}

src/ClientboundAttributeLayerSyncPacket.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ public function getPayload() : AttributeLayerSyncPayload{ return $this->payload;
4141

4242
protected function decodePayload(ByteBufferReader $in, int $protocolId) : void{
4343
$this->payload = match(VarInt::readUnsignedInt($in)){
44-
AttributeUpdateLayers::ID => AttributeUpdateLayers::read($in),
44+
AttributeUpdateLayers::ID => AttributeUpdateLayers::read($in, $protocolId),
4545
AttributeUpdateLayerSettings::ID => AttributeUpdateLayerSettings::read($in),
46-
AttributesUpdateEnvironment::ID => AttributesUpdateEnvironment::read($in),
46+
AttributesUpdateEnvironment::ID => AttributesUpdateEnvironment::read($in, $protocolId),
4747
AttributesRemoveEnvironment::ID => AttributesRemoveEnvironment::read($in),
4848
default => throw new PacketDecodeException("Unknown ClientboundAttributeLayerSync type"),
4949
};
5050
}
5151

5252
protected function encodePayload(ByteBufferWriter $out, int $protocolId) : void{
5353
VarInt::writeUnsignedInt($out, $this->payload->getTypeId());
54-
$this->payload->write($out);
54+
$this->payload->write($out, $protocolId);
5555
}
5656

5757
public function handle(PacketHandlerInterface $handler) : bool{

src/ClientboundUpdateSoundDataPacket.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public function getServerSoundHandle() : int{ return $this->serverSoundHandle; }
3939

4040
public function getSoundEvent() : string{ return $this->soundEvent; }
4141

42-
protected function decodePayload(ByteBufferReader $in) : void{
42+
protected function decodePayload(ByteBufferReader $in, int $protocolId) : void{
4343
$this->serverSoundHandle = LE::readUnsignedLong($in);
4444
$this->soundEvent = CommonTypes::getString($in);
4545
}
4646

47-
protected function encodePayload(ByteBufferWriter $out) : void{
47+
protected function encodePayload(ByteBufferWriter $out, int $protocolId) : void{
4848
LE::writeUnsignedLong($out, $this->serverSoundHandle);
4949
CommonTypes::putString($out, $this->soundEvent);
5050
}

src/GraphicsOverrideParameterPacket.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ protected function decodePayload(ByteBufferReader $in, int $protocolId) : void{
8888
$this->unknownVector3 = CommonTypes::readOptional($in, CommonTypes::getVector3(...));
8989
}
9090
$this->biomeIdentifier = CommonTypes::getString($in);
91-
$this->playerIdentifier = CommonTypes::readOptional($in, CommonTypes::getString(...));
91+
if($protocolId >= ProtocolInfo::PROTOCOL_1_26_30){
92+
$this->playerIdentifier = CommonTypes::readOptional($in, CommonTypes::getString(...));
93+
}
9294
$this->parameterType = GraphicsOverrideParameterType::fromPacket(Byte::readUnsigned($in));
9395
$this->reset = CommonTypes::getBool($in);
9496
}
@@ -103,7 +105,9 @@ protected function encodePayload(ByteBufferWriter $out, int $protocolId) : void{
103105
CommonTypes::writeOptional($out, $this->unknownVector3, CommonTypes::putVector3(...));
104106
}
105107
CommonTypes::putString($out, $this->biomeIdentifier);
106-
CommonTypes::writeOptional($out, $this->playerIdentifier, CommonTypes::putString(...));
108+
if($protocolId >= ProtocolInfo::PROTOCOL_1_26_30){
109+
CommonTypes::writeOptional($out, $this->playerIdentifier, CommonTypes::putString(...));
110+
}
107111
Byte::writeUnsigned($out, $this->parameterType->value);
108112
CommonTypes::putBool($out, $this->reset);
109113
}

src/PartyDestinationCookieResponsePacket.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public function getCookie() : string{ return $this->cookie; }
3838

3939
public function isAccepted() : bool{ return $this->accepted; }
4040

41-
protected function decodePayload(ByteBufferReader $in) : void{
41+
protected function decodePayload(ByteBufferReader $in, int $protocolId) : void{
4242
$this->cookie = CommonTypes::getString($in);
4343
$this->accepted = CommonTypes::getBool($in);
4444
}
4545

46-
protected function encodePayload(ByteBufferWriter $out) : void{
46+
protected function encodePayload(ByteBufferWriter $out, int $protocolId) : void{
4747
CommonTypes::putString($out, $this->cookie);
4848
CommonTypes::putBool($out, $this->accepted);
4949
}

src/SendPartyDestinationCookiePacket.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ public function getIntent() : string{ return $this->intent; }
4242

4343
public function getDestinationName() : string{ return $this->destinationName; }
4444

45-
protected function decodePayload(ByteBufferReader $in) : void{
45+
protected function decodePayload(ByteBufferReader $in, int $protocolId) : void{
4646
$this->cookie = CommonTypes::getString($in);
4747
$this->intent = CommonTypes::getString($in);
4848
$this->destinationName = CommonTypes::getString($in);
4949
}
5050

51-
protected function encodePayload(ByteBufferWriter $out) : void{
51+
protected function encodePayload(ByteBufferWriter $out, int $protocolId) : void{
5252
CommonTypes::putString($out, $this->cookie);
5353
CommonTypes::putString($out, $this->intent);
5454
CommonTypes::putString($out, $this->destinationName);

src/SubChunkRequestPacket.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
use pmmp\encoding\ByteBufferReader;
1818
use pmmp\encoding\ByteBufferWriter;
19+
use pmmp\encoding\LE;
1920
use pmmp\encoding\VarInt;
2021
use pocketmine\network\mcpe\protocol\types\SubChunkPosition;
2122
use pocketmine\network\mcpe\protocol\types\SubChunkPositionOffset;
@@ -57,24 +58,38 @@ public function getEntries() : array{ return $this->entries; }
5758

5859
protected function decodePayload(ByteBufferReader $in, int $protocolId) : void{
5960
$this->dimension = VarInt::readSignedInt($in);
61+
if($protocolId <= ProtocolInfo::PROTOCOL_1_26_20){
62+
$this->basePosition = SubChunkPosition::read($in);
63+
}
6064

6165
$this->entries = [];
62-
for($i = 0, $count = VarInt::readUnsignedInt($in); $i < $count; $i++){
66+
for($i = 0, $count = $protocolId >= ProtocolInfo::PROTOCOL_1_26_30 ? VarInt::readUnsignedInt($in) : LE::readUnsignedInt($in); $i < $count; $i++){
6367
$this->entries[] = SubChunkPositionOffset::read($in);
6468
}
6569

66-
$this->basePosition = SubChunkPosition::read($in, true);
70+
if($protocolId >= ProtocolInfo::PROTOCOL_1_26_30){
71+
$this->basePosition = SubChunkPosition::read($in, true);
72+
}
6773
}
6874

6975
protected function encodePayload(ByteBufferWriter $out, int $protocolId) : void{
7076
VarInt::writeSignedInt($out, $this->dimension);
77+
if($protocolId <= ProtocolInfo::PROTOCOL_1_26_20){
78+
$this->basePosition->write($out);
79+
}
7180

72-
VarInt::writeUnsignedInt($out, count($this->entries));
81+
if($protocolId >= ProtocolInfo::PROTOCOL_1_26_30){
82+
LE::writeUnsignedInt($out, count($this->entries));
83+
}else{
84+
VarInt::writeUnsignedInt($out, count($this->entries));
85+
}
7386
foreach($this->entries as $entry){
7487
$entry->write($out);
7588
}
7689

77-
$this->basePosition->write($out, true);
90+
if($protocolId >= ProtocolInfo::PROTOCOL_1_26_30){
91+
$this->basePosition->write($out, true);
92+
}
7893
}
7994

8095
public function handle(PacketHandlerInterface $handler) : bool{

src/types/AttributeEnvironment.php

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use pmmp\encoding\ByteBufferReader;
1818
use pmmp\encoding\ByteBufferWriter;
1919
use pmmp\encoding\LE;
20+
use pocketmine\network\mcpe\protocol\ProtocolInfo;
2021
use pocketmine\network\mcpe\protocol\serializer\CommonTypes;
2122

2223
/**
@@ -57,16 +58,18 @@ public function getLocalTransitionTicks() : int{ return $this->localTransitionTi
5758

5859
public function isNoiseTransition() : bool{ return $this->noiseTransition; }
5960

60-
public static function read(ByteBufferReader $in) : self{
61+
public static function read(ByteBufferReader $in, int $protocolId) : self{
6162
$name = CommonTypes::getString($in);
6263
$fromAttribute = CommonTypes::readOptional($in, AttributeValue::read(...));
6364
$attribute = AttributeValue::read($in);
6465
$toAttribute = CommonTypes::readOptional($in, AttributeValue::read(...));
6566
$currentTransitionTicks = LE::readUnsignedInt($in);
6667
$totalTransitionTicks = LE::readUnsignedInt($in);
6768
$easeType = CommonTypes::getString($in);
68-
$localTransitionTicks = LE::readUnsignedInt($in);
69-
$noiseTransition = CommonTypes::getBool($in);
69+
if($protocolId >= ProtocolInfo::PROTOCOL_1_26_30){
70+
$localTransitionTicks = LE::readUnsignedInt($in);
71+
$noiseTransition = CommonTypes::getBool($in);
72+
}
7073

7174
return new self(
7275
$name,
@@ -76,20 +79,22 @@ public static function read(ByteBufferReader $in) : self{
7679
$currentTransitionTicks,
7780
$totalTransitionTicks,
7881
$easeType,
79-
$localTransitionTicks,
80-
$noiseTransition
82+
$localTransitionTicks ?? 0,
83+
$noiseTransition ?? false
8184
);
8285
}
8386

84-
public function write(ByteBufferWriter $out) : void{
87+
public function write(ByteBufferWriter $out, int $protocolId) : void{
8588
CommonTypes::putString($out, $this->name);
8689
CommonTypes::writeOptional($out, $this->fromAttribute, fn(ByteBufferWriter $out, AttributeValue $value) => $value->write($out));
8790
$this->attribute->write($out);
8891
CommonTypes::writeOptional($out, $this->toAttribute, fn(ByteBufferWriter $out, AttributeValue $value) => $value->write($out));
8992
LE::writeUnsignedInt($out, $this->currentTransitionTicks);
9093
LE::writeUnsignedInt($out, $this->totalTransitionTicks);
9194
CommonTypes::putString($out, $this->easeType);
92-
LE::writeUnsignedInt($out, $this->localTransitionTicks);
93-
CommonTypes::putBool($out, $this->noiseTransition);
95+
if($protocolId >= ProtocolInfo::PROTOCOL_1_26_30){
96+
LE::writeUnsignedInt($out, $this->localTransitionTicks);
97+
CommonTypes::putBool($out, $this->noiseTransition);
98+
}
9499
}
95100
}

src/types/AttributeLayer.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use pmmp\encoding\ByteBufferReader;
1818
use pmmp\encoding\ByteBufferWriter;
1919
use pmmp\encoding\VarInt;
20+
use pocketmine\network\mcpe\protocol\ProtocolInfo;
2021
use pocketmine\network\mcpe\protocol\serializer\CommonTypes;
2122
use function count;
2223

@@ -51,35 +52,39 @@ public function getSettings() : AttributeLayerSettings{ return $this->settings;
5152
*/
5253
public function getAttributes() : array{ return $this->attributes; }
5354

54-
public static function read(ByteBufferReader $in) : self{
55+
public static function read(ByteBufferReader $in, int $protocolId) : self{
5556
$name = CommonTypes::getString($in);
56-
$noiseName = CommonTypes::readOptional($in, CommonTypes::getString(...));
57+
if($protocolId >= ProtocolInfo::PROTOCOL_1_26_30){
58+
$noiseName = CommonTypes::readOptional($in, CommonTypes::getString(...));
59+
}
5760
$dimension = VarInt::readUnsignedInt($in);
5861
$settings = AttributeLayerSettings::read($in);
5962

6063
$attributes = [];
6164
for($i = 0, $len = VarInt::readUnsignedInt($in); $i < $len; ++$i){
62-
$attributes[] = AttributeEnvironment::read($in);
65+
$attributes[] = AttributeEnvironment::read($in, $protocolId);
6366
}
6467

6568
return new self(
6669
$name,
67-
$noiseName,
70+
$noiseName ?? null,
6871
$dimension,
6972
$settings,
7073
$attributes,
7174
);
7275
}
7376

74-
public function write(ByteBufferWriter $out) : void{
77+
public function write(ByteBufferWriter $out, int $protocolId) : void{
7578
CommonTypes::putString($out, $this->name);
76-
CommonTypes::writeOptional($out, $this->name, CommonTypes::putString(...));
79+
if($protocolId >= ProtocolInfo::PROTOCOL_1_26_30){
80+
CommonTypes::writeOptional($out, $this->name, CommonTypes::putString(...));
81+
}
7782
VarInt::writeUnsignedInt($out, $this->dimension);
7883
$this->settings->write($out);
7984

8085
VarInt::writeUnsignedInt($out, count($this->attributes));
8186
foreach($this->attributes as $attribute){
82-
$attribute->write($out);
87+
$attribute->write($out, $protocolId);
8388
}
8489
}
8590
}

src/types/AttributeLayerSyncPayload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ abstract class AttributeLayerSyncPayload{
2323

2424
abstract public function getTypeId() : int;
2525

26-
abstract public function write(ByteBufferWriter $out) : void;
26+
abstract public function write(ByteBufferWriter $out, int $protocolId) : void;
2727
}

0 commit comments

Comments
 (0)