Added resource packs support

This commit is contained in:
Dylan K. Taylor
2017-03-10 20:00:31 +00:00
parent 1f2b584400
commit d41bdfc31c
12 changed files with 370 additions and 40 deletions

View File

@ -31,21 +31,22 @@ class ResourcePackChunkDataPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_DATA_PACKET;
public $packId;
public $unknown1;
public $unknown2;
public $chunkIndex;
public $progress;
public $data;
public function decode(){
$this->packId = $this->getString();
$this->unknown1 = $this->getLInt();
$this->unknown2 = $this->getLLong();
$this->chunkIndex = $this->getLInt();
$this->progress = $this->getLLong();
$this->data = $this->get($this->getLInt());
}
public function encode(){
$this->reset();
$this->putString($this->packId);
$this->putLInt($this->unknown1);
$this->putLLong($this->unknown2);
$this->putLInt($this->chunkIndex);
$this->putLLong($this->progress);
$this->putLInt(strlen($this->data));
$this->put($this->data);
}

View File

@ -31,17 +31,17 @@ class ResourcePackChunkRequestPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_CHUNK_REQUEST_PACKET;
public $packId;
public $unknown;
public $chunkIndex;
public function decode(){
$this->packId = $this->getString();
$this->unknown = $this->getLInt();
$this->chunkIndex = $this->getLInt();
}
public function encode(){
$this->reset();
$this->putString($this->packId);
$this->putLInt($this->unknown);
$this->putLInt($this->chunkIndex);
}
public function handle(NetworkSession $session) : bool{

View File

@ -31,26 +31,26 @@ class ResourcePackDataInfoPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::RESOURCE_PACK_DATA_INFO_PACKET;
public $packId;
public $int1;
public $int2;
public $packSize;
public $unknown;
public $maxChunkSize;
public $chunkCount;
public $compressedPackSize;
public $sha256;
public function decode(){
$this->packId = $this->getString();
$this->int1 = $this->getLInt();
$this->int2 = $this->getLInt();
$this->packSize = $this->getLLong();
$this->unknown = $this->getString();
$this->maxChunkSize = $this->getLInt();
$this->chunkCount = $this->getLInt();
$this->compressedPackSize = $this->getLLong();
$this->sha256 = $this->getString();
}
public function encode(){
$this->reset();
$this->putString($this->packId);
$this->putLInt($this->int1);
$this->putLInt($this->int2);
$this->putLLong($this->packSize);
$this->putString($this->unknown);
$this->putLInt($this->maxChunkSize);
$this->putLInt($this->chunkCount);
$this->putLLong($this->compressedPackSize);
$this->putString($this->sha256);
}
public function handle(NetworkSession $session) : bool{

View File

@ -26,6 +26,7 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\resourcepacks\ResourcePack;
use pocketmine\resourcepacks\ResourcePackInfoEntry;
class ResourcePackStackPacket extends DataPacket{
@ -33,13 +34,13 @@ class ResourcePackStackPacket extends DataPacket{
public $mustAccept = false;
/** @var ResourcePackInfoEntry[] */
/** @var ResourcePack[] */
public $behaviorPackStack = [];
/** @var ResourcePackInfoEntry[] */
/** @var ResourcePack[] */
public $resourcePackStack = [];
public function decode(){
$this->mustAccept = $this->getBool();
/*$this->mustAccept = $this->getBool();
$behaviorPackCount = $this->getLShort();
while($behaviorPackCount-- > 0){
$packId = $this->getString();
@ -52,7 +53,7 @@ class ResourcePackStackPacket extends DataPacket{
$packId = $this->getString();
$version = $this->getString();
$this->resourcePackStack[] = new ResourcePackInfoEntry($packId, $version);
}
}*/
}
public function encode(){
@ -62,13 +63,13 @@ class ResourcePackStackPacket extends DataPacket{
$this->putLShort(count($this->behaviorPackStack));
foreach($this->behaviorPackStack as $entry){
$this->putString($entry->getPackId());
$this->putString($entry->getVersion());
$this->putString($entry->getPackVersion());
}
$this->putLShort(count($this->resourcePackStack));
foreach($this->resourcePackStack as $entry){
$this->putString($entry->getPackId());
$this->putString($entry->getVersion());
$this->putString($entry->getPackVersion());
}
}

View File

@ -25,19 +25,20 @@ namespace pocketmine\network\mcpe\protocol;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\resourcepacks\ResourcePack;
use pocketmine\resourcepacks\ResourcePackInfoEntry;
class ResourcePacksInfoPacket extends DataPacket{
const NETWORK_ID = ProtocolInfo::RESOURCE_PACKS_INFO_PACKET;
public $mustAccept = false; //if true, forces client to use selected resource packs
/** @var ResourcePackInfoEntry[] */
/** @var ResourcePack[] */
public $behaviorPackEntries = [];
/** @var ResourcePackInfoEntry[] */
/** @var ResourcePack[] */
public $resourcePackEntries = [];
public function decode(){
$this->mustAccept = $this->getBool();
/*$this->mustAccept = $this->getBool();
$behaviorPackCount = $this->getLShort();
while($behaviorPackCount-- > 0){
$id = $this->getString();
@ -52,7 +53,7 @@ class ResourcePacksInfoPacket extends DataPacket{
$version = $this->getString();
$size = $this->getLLong();
$this->resourcePackEntries[] = new ResourcePackInfoEntry($id, $version, $size);
}
}*/
}
public function encode(){
@ -62,13 +63,13 @@ class ResourcePacksInfoPacket extends DataPacket{
$this->putLShort(count($this->behaviorPackEntries));
foreach($this->behaviorPackEntries as $entry){
$this->putString($entry->getPackId());
$this->putString($entry->getVersion());
$this->putString($entry->getPackVersion());
$this->putLLong($entry->getPackSize());
}
$this->putLShort(count($this->resourcePackEntries));
foreach($this->resourcePackEntries as $entry){
$this->putString($entry->getPackId());
$this->putString($entry->getVersion());
$this->putString($entry->getPackVersion());
$this->putLLong($entry->getPackSize());
}
}