protected function createEnvelope(array $requests, Position $position) : RequestEnvelope
    {
        $authInfo = null;

        $envelope = new RequestEnvelope();
        $envelope->setStatusCode(2);
        $envelope->setLatitude($position->getLatitude());
        $envelope->setLongitude($position->getLongitude());
        $envelope->setAccuracy($position->getAccuracy());
        $envelope->setRequestId($this->getRequestId());
        $envelope->setMsSinceLastLocationfix(mt_rand(700, 1200));

        // Check if we have an authentication ticket
        if ($this->ticket && !$this->ticket->hasExpired()) {
            $envelope->setAuthTicket($this->ticket->toProto());
        } else {
            if (!$this->token || $this->token->hasExpired()){
                $this->token = $this->authentication->getToken();
            }
            $authInfo = new RequestEnvelope\AuthInfo();
            $authInfo->setProvider($this->authentication->getType());
            $authToken = new RequestEnvelope\AuthInfo\JWT();
            $authToken->setContents($this->token->getToken());
            $authToken->setUnknown2(59);
            $authInfo->setToken($authToken);
            $envelope->setAuthInfo($authInfo);
        }

        foreach ($requests as $request) {
            $envelope->addRequests($request->toProtobufRequest());
        }

        // Attach the UNKNOWN_PTR_8 request if version is > 4500 and there is a GET_MAP_OBJECTS or GET_PLAYER request
        $platform8Requests = array_filter(
            $requests,
            function (Request $request) {
                return $request instanceof GetMapObjects || $request instanceof GetPlayer;
            }
        );

        if ($this->version->getVersion() > 4500 && count($platform8Requests) > 0) {
            $platform8Request = new RequestEnvelope\PlatformRequest();
            $platform8Request->setType(PlatformRequestType::UNKNOWN_PTR_8());
            $platform8Request->setRequestMessage($this->version->getPlatform8());
        }

        // Add an encrypted signature platform request to the envelope.
        $platformRequest = new RequestEnvelope\PlatformRequest();
        $platformRequest->setType(PlatformRequestType::SEND_ENCRYPTED_SIGNATURE());

        $encryptedSigRequest = new SendEncryptedSignatureRequest();
        $encryptedSigRequest->setEncryptedSignature(
            $this->generateSignature($requests, $position, $authInfo)
        );

        $platformRequest->setRequestMessage($encryptedSigRequest->toStream());
        $envelope->addPlatformRequests($platformRequest);

        $envelope->setMsSinceLastLocationfix(rand(200, 800));

        return $envelope;
    }