Exemplo n.º 1
0
void Tile::load(BitReader &bits)
{
	foreground=bits.r16();
	fgHueShift=bits.r8();
	fgColorVariant=bits.r8();
	fgMod=bits.r16();
	fgModHueShift=bits.r8();
	background=bits.r16();
	bgHueShift=bits.r8();
	bgColorVariant=bits.r8();
	bgMod=bits.r16();
	bgModHueShift=bits.r8();
	liquid=bits.r8();
	liquidPressure=bits.r8();
	bits.skip(6); //collision, dungeonid,biome,envbiome,root
}
Exemplo n.º 2
0
  bool init ( BitReader br )
  {
    br.reset();
    if ( br.getByte() != 0x64
        || br.getByte() != 0x58
        || br.getByte() != 0x20
        || br.getByte() != 0x25 )
    {
        return false;
    }

    // * dca.c dca_exss_parse_header

    br.skip(8); // user data
    _ssIndex = br.getInt(2);
    bool blownUp(br.getBool());
    _headerSize = br.getInt(blownUp ? 12 : 8);
    //hdLen = ((hdHdr[6] & 0xf) << 11) + (hdHdr[7] << 3) + ((hdHdr[8] >> 5) & 7) + 1;
    _hdSize = br.getInt(blownUp ? 20: 16) + 1;

    return true;
  }
Exemplo n.º 3
0
UInt64 WebSocketFramer::readFrame(BitReader& frame, char*& payload)
{
	assert(handshakeComplete());
	UInt64 limit = frame.limit();
	size_t offset = frame.position(); 
	//assert(offset == 0);
	
	// Read the frame header
	char header[MAX_HEADER_LENGTH];
	BitReader headerReader(header, MAX_HEADER_LENGTH);	
	frame.get(header, 2);
	UInt8 lengthByte = static_cast<UInt8>(header[1]);
	int maskOffset = 0;
	if (lengthByte & FRAME_FLAG_MASK) maskOffset += 4;
	lengthByte &= 0x7f;
	if (lengthByte + 2 + maskOffset < MAX_HEADER_LENGTH)
		frame.get(header + 2, lengthByte + maskOffset);
	else
		frame.get(header + 2, MAX_HEADER_LENGTH - 2);

	// Reserved fields
	frame.skip(2);	

	// Parse frame header
	UInt8 flags;
	char mask[4];
	headerReader.getU8(flags);	
	headerReader.getU8(lengthByte);
	_frameFlags = flags;
	UInt64 payloadLength = 0;
	int payloadOffset = 2;
	if ((lengthByte & 0x7f) == 127) {
		UInt64 l;
		headerReader.getU64(l);
		if (l > limit)
			throw std::runtime_error(util::format("WebSocket error: Insufficient buffer for payload size %" I64_FMT "u", l)); //, ws::ErrorPayloadTooBig
		payloadLength = l;
		payloadOffset += 8;
	}
	else if ((lengthByte & 0x7f) == 126) {
		UInt16 l;
		headerReader.getU16(l);
		if (l > limit)
			throw std::runtime_error(util::format("WebSocket error: Insufficient buffer for payload size %u", unsigned(l))); //, ws::ErrorPayloadTooBig
		payloadLength = l;
		payloadOffset += 2;
	}
	else {
		UInt8 l = lengthByte & 0x7f;
		if (l > limit)
			throw std::runtime_error(util::format("WebSocket error: Insufficient buffer for payload size %u", unsigned(l))); //, ws::ErrorPayloadTooBig
		payloadLength = l;
	}
	if (lengthByte & FRAME_FLAG_MASK) {	
		headerReader.get(mask, 4);
		payloadOffset += 4;
	}

	if (payloadLength > limit) //length)
		throw std::runtime_error("WebSocket error: Incomplete frame received"); //, ws::ErrorIncompleteFrame		

	// Get a reference to the start of the payload
	payload = reinterpret_cast<char*>(const_cast<char*>(frame.begin() + (offset + payloadOffset)));

	// Unmask the payload if required
	if (lengthByte & FRAME_FLAG_MASK) {
		auto p = reinterpret_cast<char*>(payload); //frame.data());
		for (UInt64 i = 0; i < payloadLength; i++) {
			p[i] ^= mask[i % 4];
		}
	}
	
	// Update frame length to include payload plus header
	frame.seek(std::size_t(offset + payloadOffset + payloadLength));
	//frame.limit(offset + payloadOffset + payloadLength);
	//int frameLength = (offset + payloadOffset);
	//assert(frame.position() == (offset + payloadOffset));

	return payloadLength;
}