size_t ClickWindow::deserialize(const Buffer& _src, size_t _offset)
{
	_offset = _pm_checkPacketId(_src, _offset);

	_offset = ReadInt8(_src, _offset, _pf_windowId);
	_offset = ReadInt16(_src, _offset, _pf_slot);
	_offset = ReadInt8(_src, _offset, _pf_button);
	_offset = ReadInt16(_src, _offset, _pf_actionNumber);
	_offset = ReadInt8(_src, _offset, _pf_mode);
	//_offset = ReadSlotData(_src, _offset, _pf_clickedItem);
	_offset = _pf_clickedItem.deserialize(_src, _offset);
	_pf_initialized = true;
	return _offset;
}
Exemple #2
0
int TargaLoader::ReadHeader(IO::ISequentialByteStream* stream)
{
	if (stream->Read(&m_header, sizeof(m_header)) != sizeof(m_header))
		throw std::exception("End of stream");

	if (	(m_header.imageType != 0) &&
			(m_header.imageType != 1) &&
			(m_header.imageType != 2) &&
			(m_header.imageType != 3) &&
			(m_header.imageType != 9) &&
			(m_header.imageType != 10) &&
			(m_header.imageType != 11) &&
			(m_header.imageType != 32) &&
			(m_header.imageType != 33))
	{
		return -1;
	}

	m_colorMapOrigin = ReadInt16(stream);
	m_colorMapLength = ReadInt16(stream);
	m_colorEntrySize = ReadInt8(stream);

	m_x = ReadInt16(stream);
	m_y = ReadInt16(stream);
	m_width = ReadInt16(stream);
	m_height = ReadInt16(stream);
	m_pixelSize = ReadInt8(stream);

	if (stream->Read(&m_flags, 1) != 1)
		throw std::exception("End of stream");

	m_id = new char[m_header.idlen];
	stream->Read(m_id, m_header.idlen);

	if (m_header.colorType > 1)
	{
		return -1;
	}

	m_pixel_size = m_pixelSize >> 3;
	
	if ((m_pixel_size < 1) || (m_pixel_size > 4))
	{
		return -1;
	}

	return 0;
}
Exemple #3
0
int Packet::ReadChar(char* buffer, int buffersize) {
	int length = ReadInt8();
	if (length <= 0) {
		strcpy(buffer, "");
		return length;
	}

	if (index+length > data.size()) { //uhoh
		strcpy(buffer, "error");
		return length;
	}

	strcpy(buffer,"");
	int i = 0;
	while (i < length) {
		if (i >= buffersize-1) break;

		char temp = data[index+i];
		if (temp != '\0' && (temp < 32 || temp > 128)) temp = 32;

		buffer[i] = temp;
		i++;
	}
	buffer[i] = '\0';

    //memcpy(&buffer, &data[index], length);
	//buffer[length] = 0; //terminate string
    index += length;	
	return length;
}
Exemple #4
0
bool VCFont::ParseKerning(std::ifstream& f)
{
	char blockType = ReadInt8(f);
	int blockSize = ReadInt32(f);

	int kerningCount = blockSize / 10;

	// Pre-Buffer data ( Used to be a bottleneck - Profiled )
	KerningPairIMR* pairsIMR = (KerningPairIMR*) malloc (sizeof(KerningPairIMR) * kerningCount);
	int size = sizeof(KerningPairIMR);
	//f.read((char*)pairsIMR, sizeof(KerningPairIMR) * kerningCount);

	for ( int i = 0; i < kerningCount; i++ )
	{
		// Truncated Endian swap ( Truncated to 8 bits, hopefully enough )
		//KerningPairIMR p = pairsIMR[i];
		//p.first = p.first >> 28;
		//p.second = p.second >> 28;
		//p.ammount = p.ammount >> 8;
		//
		//Charaters[p.second].KerningPairs[p.first] = p.ammount;
		unsigned int first = ReadInt32(f);
		unsigned int second = ReadInt32(f);
		short ammount = ReadInt16(f);
		//Int8 sh = 0;

		Charaters[second].KerningPairs[first] = ammount;

	}

	free(pairsIMR);

	return true;
}
size_t SpawnObject::deserialize(const Buffer& _src, size_t _offset)
{
	_offset = _pm_checkPacketId(_src, _offset);

	_offset = ReadInt32(_src, _offset, _pf_entityId);
	_offset = ReadInt8(_src, _offset, _pf_type);
	_offset = ReadInt32(_src, _offset, _pf_x);
	_offset = ReadInt32(_src, _offset, _pf_y);
	_offset = ReadInt32(_src, _offset, _pf_z);
	_offset = ReadInt8(_src, _offset, _pf_pitch);
	_offset = ReadInt8(_src, _offset, _pf_yaw);
	_offset = _pf_objectData.deserialize(_src, _offset);

	_pf_initialized = true;
	return _offset;
}
Exemple #6
0
static int32_t CalcFileChecksum(myint fd, myint len)
{
	int8_t buf[32];
	
	int32_t cs;
	myint i, j;
	int8_t c1;
	
	cs = 0;
	c1 = ReadInt8(fd);
	
	len--;
	while (len > 0) {
		i = 32;
		if (len < i) {
			i = len;
		}
		
		ReadBytes(fd, (byte *)buf, i);
		
		for (j = 0; j < i; j++) {
			cs += c1 ^ buf[j];
			c1 = buf[j];
		}
		
		len -= 32;
	}
	
	return cs;
}
size_t ClientStatuses::deserialize(const Buffer& _src, size_t _offset)
{
	_offset = _pm_checkPacketId(_src, _offset);

	_offset = ReadInt8(_src, _offset, _pf_payload);
	_pf_initialized = true;
	return _offset;
}
size_t CloseWIndow::deserialize(const Buffer& _src, size_t _offset)
{
	_offset = _pm_checkPacketId(_src, _offset);

	_offset = ReadInt8(_src, _offset, _pf_windowId);
	_pf_initialized = true;
	return _offset;
}
Exemple #9
0
bool VCFont::ParseCommon(std::ifstream& f)
{
	char blockType = ReadInt8(f);
	int blockSize = ReadInt32(f);

	f.read((char*) &Common, 15);
	
	return true;
}
size_t DisplayScoreboard::deserialize(const Buffer& _src, size_t _offset)
{
	_offset = _pm_checkPacketId(_src, _offset);

	_offset = ReadInt8(_src, _offset, _pf_position);
	_offset = ReadString16(_src, _offset, _pf_scoreName);
	_pf_initialized = true;
	return _offset;
}
size_t EntityStatus::deserialize(const Buffer& _src, size_t _offset)
{
	_offset = _pm_checkPacketId(_src, _offset);

	_offset = ReadInt32(_src, _offset, _pf_entityId);
	_offset = ReadInt8(_src, _offset, _pf_entityStatus);
	_pf_initialized = true;
	return _offset;
}
size_t UpdateWindowProperty::deserialize(const Buffer& _src, size_t _offset)
{
	_offset = _pm_checkPacketId(_src, _offset);

	_offset = ReadInt8(_src, _offset, _pf_windowId);
	_offset = ReadInt16(_src, _offset, _pf_property);
	_offset = ReadInt16(_src, _offset, _pf_value);
	_pf_initialized = true;
	return _offset;
}
size_t Handshake::deserialize(const Buffer& _src, size_t _offset)
{
	_offset = _pm_checkPacketId(_src, _offset);

	_offset = ReadInt8(_src, _offset, _pf_protVer);
	_offset = ReadString16(_src, _offset, _pf_username);
	_offset = ReadString16(_src, _offset, _pf_host);
	_offset = ReadInt32(_src, _offset, _pf_port);
	_pf_initialized = true;
	return _offset;
}
Exemple #14
0
TEnumValueType CObjectIStreamJson::ReadEnum(const CEnumeratedTypeValues& values)
{
    TEnumValueType value;
    char c = SkipWhiteSpace();
    if (c == '\"') {
        value = values.FindValue( ReadValue());
    } else {
        value = (TEnumValueType)ReadInt8();
    }
    return value;
}
Exemple #15
0
bool VCFont::ParseInfo(std::ifstream& f)
{
	char blockType = ReadInt8(f);
	int blockSize = ReadInt32(f);

	f.read((char*) &Info, sizeof(InfoHeader));

	while(true)
	{
		char inC = ReadInt8(f);

		if ( inC == 0 )
			break;

		FontName.push_back(inC);
	}

	Size = Info.fontSize;

	return true;
}
size_t SpawnGlobalEntity::deserialize(const Buffer& _src, size_t _offset)
{
	_offset = _pm_checkPacketId(_src, _offset);

	_offset = ReadInt32(_src, _offset, _pf_entityId);
	_offset = ReadInt8(_src, _offset, _pf_type);
	_offset = ReadInt32(_src, _offset, _pf_x);
	_offset = ReadInt32(_src, _offset, _pf_y);
	_offset = ReadInt32(_src, _offset, _pf_z);
	_pf_initialized = true;
	return _offset;
}
size_t SetSlot::deserialize(const Buffer& _src, size_t _offset)
{
	_offset = _pm_checkPacketId(_src, _offset);

	_offset = ReadInt8(_src, _offset, _pf_windowId);
	_offset = ReadInt16(_src, _offset, _pf_slotNum);

	_offset = SlotData().deserialize(_src, _offset);

	_pf_initialized = true;
	return _offset;
}
Exemple #18
0
bool VCFont::ParsePages(std::ifstream& f)
{
	char blockType = ReadInt8(f);
	int blockSize = ReadInt32(f);

	if ( Common.pages != 1 )
	{
		VC_ERROR("Only 1 font page per font is supported.");
	}

	while(true)
	{
		char inC = ReadInt8(f);

		if ( inC == 0 )
			break;

		m_imageFileName.push_back(inC);
	}
	
	return true;
}
size_t DestroyEntity::deserialize(const Buffer& _src, size_t _offset)
{
	_offset = _pm_checkPacketId(_src, _offset);

	_offset = ReadInt8(_src, _offset, _pf_entityCount);

	_pf_entityIds.resize(_pf_entityCount);

	for(int i = 0; i < _pf_entityCount; ++i)
		_offset = ReadInt32(_src, _offset, _pf_entityIds[i]);

	_pf_initialized = true;
	return _offset;
}
Exemple #20
0
bool VCFont::ParseCharacters(std::ifstream& f)
{
	char blockType = ReadInt8(f);
	int blockSize = ReadInt32(f);

	int charCount = blockSize / 20;

	for ( int i = 0; i < charCount; i++ )
	{
		unsigned int id = ReadInt32(f);
		f.read((char*) &Charaters[id], 16);
	}

	return true;
}
Exemple #21
0
	haBool32 ReadBString( haString text )
	{
		haInt8 tmp1 = 0, tmp2 = 0;
		haInt16 tmp;
		if( !m_BufferEnabled )
		{
			fread( &tmp1, 1, 1, m_File );
			if( tmp1 & 0x80 )
				fread( &tmp2, 1, 1, m_File );
			tmp = (tmp2<<7)|(tmp1&0x7F);
			fread( text, 1, tmp, m_File );
		}
		else
		{
			tmp1 = ReadInt8( );
			if( tmp1 & 0x80 )
				tmp2 = ReadInt8( );
			tmp = (tmp2<<7)|(tmp1&0x7F);
			Read( text, tmp );
			text[tmp] = 0;
		}
		text[tmp] = 0;
		return true;
	};
Exemple #22
0
	haBool32 ReadZString( haString text )
	{
		char* tmp = text;
		*tmp = 0;
		while( 1 )
		{
			if( !m_BufferEnabled )
			{
				fread( tmp, 1, 1, m_File );
			}
			else
			{
				*tmp = ReadInt8( );
			}
			if( *tmp == 0 )
				break;
			tmp++;
		}
		return true;
	};
Exemple #23
0
size_t SlotData::deserialize(const Buffer& _src, size_t _offset)
{
	//_pm_checkPacketId(_src);

	_offset = ReadInt(_src, _offset, _pf_itemId);
	
	if(_pf_itemId != -1)
	{
		_offset = ReadInt8(_src, _offset, _pf_itemCount);
		_offset = ReadInt16(_src, _offset, _pf_itemDamage);
		_offset = ReadInt16(_src, _offset, _pf_nbtDataLen);
		
		if(_pf_nbtDataLen != -1)
		{
			_offset = ReadByteArray(_src, _offset, _pf_nbtDataLen, _pf_nbtData);
			// Дальше должно быть разжатие, но потом
		}
	}
	
	return _offset;
	//_pf_initialized = true;
}
Exemple #24
0
int LuaPacket::Dump(lua_State* L)
{
    // Save old rpos and seek to the beginning (without the opcode)
    size_t oldrpos = rpos();
    rpos(sizeof(uint32_t));

    uint32_t pushed = 0;

    std::string value = lua_tostring(L, 1);
    std::vector<std::string> parts = Utils::Split(value, ' ');

    if (parts.size() < 1)
        return luaL_argerror(L, 1, "Invalid dump format");

    for (uint32_t i = 0; i < parts.size(); i++)
    {
        if (parts[i] == "int8")
        {
            ReadInt8(L);
            pushed++;
        }
        else if (parts[i] == "int16")
        {
            ReadInt16(L);
            pushed++;
        }
        else if (parts[i] == "int32")
        {
            ReadInt32(L);
            pushed++;
        }
        else if (parts[i] == "int64")
        {
            ReadInt64(L);
            pushed++;
        }
        else if (parts[i] == "int128")
        {
            ReadInt128(L);
            pushed++;
        }
        else if (parts[i] == "float")
        {
            ReadFloat(L);
            pushed++;
        }
        else if (parts[i] == "double")
        {
            ReadDouble(L);
            pushed++;
        }
        else if (parts[i] == "string")
        {
            ReadString(L);
            pushed++;
        }
        else if (parts[i] == "bit")
        {
            ReadBit(L);
            pushed++;
        }
    }

    // Restore rpos
    rpos(oldrpos);
    return pushed;
}
Exemple #25
0
myint ReadConfig()
{
#ifndef EMBEDDED
	myint fd, configokay;
	char buf[8];
	int32_t version, v;
#ifdef ENABLE_CONTROLS
	myint i;
#endif
	
	configokay = 0;
	
	fd = OpenRead(configname);
	
	if (fd != -1) {
		SetDefaults();
		
		ReadBytes(fd, (byte *)buf, 8);
		if (strncmp(buf, GAMEHDR, 8))
			goto configend;
		
		ReadBytes(fd, (byte *)buf, 4);
		if (strncmp(buf, CFGTYPE, 4))
			goto configend;
		
		version = ReadInt32(fd);
		if (version != 0xFFFFFFFF && version != 0x00000000)
			goto configend;
		
		ReadBytes(fd, (byte *)buf, 4);
		if (strncmp(buf, GAMETYPE, 4))
			goto configend;
		
		ReadInt32(fd);	/* skip over time */
		ReadInt32(fd);	/* skip over padding */
		
		v = ReadInt32(fd);	/* get checksum */
		if (v != CalcFileChecksum(fd, ReadLength(fd) - 32))
			goto configend;
		
		ReadSeek(fd, 32, SEEK_SET);
		
#ifdef ENABLE_HIGHSCORES
		for (i = 0; i < 7; i++) { /* MaxScores = 7 */
			ReadBytes(fd, (byte *)Scores[i].name, 58);
			Scores[i].score = ReadInt32(fd);
			Scores[i].completed = ReadInt32(fd);
			Scores[i].episode = ReadInt32(fd);
		}
#endif
		
		viewsize = ReadInt32(fd);
		
		/* load the new data */
		if (version == 0x00000000) {
			/* sound config, etc. */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			ReadInt32(fd); /* padding */
			
#ifdef ENABLE_CONTROLS
			/* direction keys */	
			for (i = 0; i < 4; i++) {
				dirscan[i] = ReadInt32(fd);
			}
			
			/* other game keys */
			for (i = 0; i < 8; i++) { /* NUMBUTTONS = 8 */
				buttonscan[i] = ReadInt32(fd);
			}
			
			/* mouse enabled */
			mouseenabled = ReadInt8(fd);
			
			/* mouse buttons */
			for (i = 0; i < 4; i++) {
				buttonmouse[i] = ReadInt32(fd);
			}
#endif
			
			/* mouse adjustment */
			mouseadjustment = ReadInt32(fd);
			
			/* unimplemented joystick */
			v = ReadInt32(fd);
			if (v != 0xFFFFFFFF) {
			}
		}
#ifndef EMBEDDED
#ifdef UPLOAD		
		MainMenu[readthis].active = 1;
		MainItems.curpos = 0;
#endif
#endif

		configokay = 1;
	} 
	
configend:	
	
	if (fd != -1)
		CloseRead(fd);
	
	if (!configokay) {
		SetDefaults();
	}
#else
	SetDefaults();
#endif
	
	return 0;
}
Exemple #26
0
	haBool32 SkipZString( )
	{
		while( ReadInt8( ) != 0 );
		return true;
	};
Exemple #27
0
FRs3dMovie::FRs3dMovie(){
   MO_CLEAR(_pAnimation);
   _playCd = 0;
   _frameBegin = 0;
   _frameEnd = 0;
   _frameRate = 0.0f;
}

//============================================================
// <T>析构资源3D帧。</T>
//============================================================
FRs3dMovie::~FRs3dMovie(){
}

//============================================================
// <T>从输入流里反序列化信息内容</T>
//
// @param pInput 输入流
// @return 处理结果
//============================================================
TResult FRs3dMovie::Unserialize(IDataInput* pInput){
   MO_CHECK(pInput, return ENull);
   _playCd = pInput->ReadInt8();
   _frameBegin = pInput->ReadInt16();
   _frameEnd = pInput->ReadInt16();
   _frameRate = pInput->ReadFloat();
   return ESuccess;
}

MO_NAMESPACE_END
bool InteropInputStream::ReadBool()
{
    return ReadInt8() == 1;
}
Exemple #29
0
FRs3dMaterial::~FRs3dMaterial(){
}

//============================================================
// <T>从输入流里反序列化信息内容</T>
//
// @param pInput 输入流
// @return 处理结果
//============================================================
TResult FRs3dMaterial::Unserialize(IDataInput* pInput){
   MO_CHECK(pInput, return ENull);
   // 读取父信息
   FResource3d::Unserialize(pInput);
   _info.Unserialize(pInput);
   // 读取纹理集合
   TInt count = pInput->ReadInt8();
   for(TInt n = 0; n < count; n++){
      FRs3dMaterialTexture* pTexture = FRs3dMaterialTexture::InstanceCreate();
      pTexture->Unserialize(pInput);
      _textures.Push(pTexture);
   }
   return ESuccess;
}
      
//============================================================
// <T>重置数据。</T>
//============================================================
void FRs3dMaterial::Reset(){
   _info.Reset();
}