Example #1
0
// virtual
BOOL LLInventoryItem::unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num)
{
	msg->getUUIDFast(block, _PREHASH_ItemID, mUUID, block_num);
	msg->getUUIDFast(block, _PREHASH_FolderID, mParentUUID, block_num);
	mPermissions.unpackMessage(msg, block, block_num);
	msg->getUUIDFast(block, _PREHASH_AssetID, mAssetUUID, block_num);

	S8 type;
	msg->getS8Fast(block, _PREHASH_Type, type, block_num);
	mType = static_cast<LLAssetType::EType>(type);
	if (mType == LLAssetType::AT_LINK || mType == LLAssetType::AT_LINK_FOLDER)
	{
		gHippoGridManager->getConnectedGrid()->setSupportsInvLinks(true);
	}
	msg->getS8(block, "InvType", type, block_num);
	mInventoryType = static_cast<LLInventoryType::EType>(type);
	mPermissions.initMasks(mInventoryType);

	msg->getU32Fast(block, _PREHASH_Flags, mFlags, block_num);

	mSaleInfo.unpackMultiMessage(msg, block, block_num);

	msg->getStringFast(block, _PREHASH_Name, mName, block_num);
	LLStringUtil::replaceNonstandardASCII(mName, ' ');

	msg->getStringFast(block, _PREHASH_Description, mDescription, block_num);
	LLStringUtil::replaceNonstandardASCII(mDescription, ' ');

	S32 date;
	msg->getS32(block, "CreationDate", date, block_num);
	mCreationDate = date;

	U32 local_crc = getCRC32();
	U32 remote_crc = 0;
	msg->getU32(block, "CRC", remote_crc, block_num);
//#define CRC_CHECK
#ifdef CRC_CHECK
	if(local_crc == remote_crc)
	{
		lldebugs << "crc matches" << llendl;
		return TRUE;
	}
	else
	{
		llwarns << "inventory crc mismatch: local=" << std::hex << local_crc
				<< " remote=" << remote_crc << std::dec << llendl;
		return FALSE;
	}
#else
	return (local_crc == remote_crc);
#endif
}
Example #2
0
// virtual
BOOL LLInventoryItem::unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num)
{
	msg->getUUIDFast(block, _PREHASH_ItemID, mUUID, block_num);
	msg->getUUIDFast(block, _PREHASH_FolderID, mParentUUID, block_num);
	mPermissions.unpackMessage(msg, block, block_num);
	msg->getUUIDFast(block, _PREHASH_AssetID, mAssetUUID, block_num);

	S8 type;
	msg->getS8Fast(block, _PREHASH_Type, type, block_num);
	mType = static_cast<LLAssetType::EType>(type);
	msg->getS8(block, "InvType", type, block_num);
	mInventoryType = static_cast<LLInventoryType::EType>(type);

	msg->getU32Fast(block, _PREHASH_Flags, mFlags, block_num);

	mSaleInfo.unpackMultiMessage(msg, block, block_num);

	char name[DB_INV_ITEM_NAME_BUF_SIZE];	/* Flawfinder: ignore */
	msg->getStringFast(block, _PREHASH_Name, DB_INV_ITEM_NAME_BUF_SIZE, name, block_num);
	mName.assign(name);
	LLString::replaceNonstandardASCII(mName, ' ');

	char desc[DB_INV_ITEM_DESC_BUF_SIZE];	/* Flawfinder: ignore */
	msg->getStringFast(block, _PREHASH_Description, DB_INV_ITEM_DESC_BUF_SIZE, desc, block_num);
	mDescription.assign(desc);
	LLString::replaceNonstandardASCII(mDescription, ' ');

	msg->getS32(block, "CreationDate", mCreationDate, block_num);

	U32 local_crc = getCRC32();
	U32 remote_crc = 0;
	msg->getU32(block, "CRC", remote_crc, block_num);
//#define CRC_CHECK
#ifdef CRC_CHECK
	if(local_crc == remote_crc)
	{
		lldebugs << "crc matches" << llendl;
		return TRUE;
	}
	else
	{
		llwarns << "inventory crc mismatch: local=" << std::hex << local_crc
				<< " remote=" << remote_crc << std::dec << llendl;
		return FALSE;
	}
#else
	return (local_crc == remote_crc);
#endif
}
Example #3
0
bool loadHighscoreFromFile()
{
	unsigned int version;
	unsigned int crc32;

	String filename = String(sgLevel.filename) + EXT_HIGHSCORE;
	FILE *file = fopen(filename, "rt");

	if (!file)
	{
		return false;
	}

	/* version number */
	if (fscanf(file, "v%u", &version) != 1 || version > THIS_HIGHSCORE_VERSION)
	{
		fprintf(stderr, "incompatible version number: %u\n", version);
		fclose(file);
		return false;
	}

	if (fscanf(file, "%x\n", &crc32) != 1 || crc32 != sgLevel.crc32)
	{
		fprintf(stderr, "1st checksum mismatch: %s\n", (const char*) filename);
		fclose(file);
		return false;
	}

	setCRC32(sgLevel.crc32);

	sgLevel.cntScoreCols = readByte(file);

	for (int i = 0; i < sgLevel.cntScoreCols; i++)
	{
		sgLevel.scores[i].tenthSecond = readInt(file);
		readString(file, sgLevel.scores[i].name);
	}

	if (fscanf(file, "%x\n", &crc32) != 1 || crc32 != getCRC32())
	{
		fprintf(stderr, "2st checksum mismatch: %s\n", (const char*) filename);
		fclose(file);
		return false;
	}

	fclose(file);

	return true;
}
// virtual
BOOL LLInventoryItem::unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num)
{
	msg->getUUIDFast(block, _PREHASH_ItemID, mUUID, block_num);
	msg->getUUIDFast(block, _PREHASH_FolderID, mParentUUID, block_num);
	mPermissions.unpackMessage(msg, block, block_num);
	msg->getUUIDFast(block, _PREHASH_AssetID, mAssetUUID, block_num);

	S8 type;
	msg->getS8Fast(block, _PREHASH_Type, type, block_num);
	mType = static_cast<LLAssetType::EType>(type);
	msg->getS8(block, "InvType", type, block_num);
	mInventoryType = static_cast<LLInventoryType::EType>(type);
	mPermissions.initMasks(mInventoryType);

	msg->getU32Fast(block, _PREHASH_Flags, mFlags, block_num);

	mSaleInfo.unpackMultiMessage(msg, block, block_num);

	msg->getStringFast(block, _PREHASH_Name, mName, block_num);
	LLStringUtil::replaceNonstandardASCII(mName, ' ');

	msg->getStringFast(block, _PREHASH_Description, mDescription, block_num);
	LLStringUtil::replaceNonstandardASCII(mDescription, ' ');

	S32 date;
	msg->getS32(block, "CreationDate", date, block_num);
	mCreationDate = date;

	U32 local_crc = getCRC32();
	U32 remote_crc = 0;
	msg->getU32(block, "CRC", remote_crc, block_num);
//#define CRC_CHECK
#ifdef CRC_CHECK
	if(local_crc == remote_crc)
	{
		LL_DEBUGS() << "crc matches" << LL_ENDL;
		return TRUE;
	}
	else
	{
		LL_WARNS() << "inventory crc mismatch: local=" << std::hex << local_crc
				<< " remote=" << remote_crc << std::dec << LL_ENDL;
		return FALSE;
	}
#else
	return (local_crc == remote_crc);
#endif
}
Example #5
0
// virtual
void LLInventoryItem::packMessage(LLMessageSystem* msg) const
{
	msg->addUUIDFast(_PREHASH_ItemID, mUUID);
	msg->addUUIDFast(_PREHASH_FolderID, mParentUUID);
	mPermissions.packMessage(msg);
	msg->addUUIDFast(_PREHASH_AssetID, mAssetUUID);
	S8 type = static_cast<S8>(mType);
	msg->addS8Fast(_PREHASH_Type, type);
	type = static_cast<S8>(mInventoryType);
	msg->addS8Fast(_PREHASH_InvType, type);
	msg->addU32Fast(_PREHASH_Flags, mFlags);
	mSaleInfo.packMessage(msg);
	msg->addStringFast(_PREHASH_Name, mName);
	msg->addStringFast(_PREHASH_Description, mDescription);
	msg->addS32Fast(_PREHASH_CreationDate, mCreationDate);
	U32 crc = getCRC32();
	msg->addU32Fast(_PREHASH_CRC, crc);
}
Example #6
0
// virtual
void LLViewerInventoryItem::packMessage(LLMessageSystem* msg) const
{
	LL_INFOS("Inventory") << " UDP Rez/UpdateObject of UUID " << mUUID << " parent = " << mParentUUID << " type= " << mType << " transaction= "<< mTransactionID << LL_ENDL; // OGPX
	msg->addUUIDFast(_PREHASH_ItemID, mUUID);
	msg->addUUIDFast(_PREHASH_FolderID, mParentUUID);
	mPermissions.packMessage(msg);
	msg->addUUIDFast(_PREHASH_TransactionID, mTransactionID);
	S8 type = static_cast<S8>(mType);
	msg->addS8Fast(_PREHASH_Type, type);
	type = static_cast<S8>(mInventoryType);
	msg->addS8Fast(_PREHASH_InvType, type);
	msg->addU32Fast(_PREHASH_Flags, mFlags);
	mSaleInfo.packMessage(msg);
	msg->addStringFast(_PREHASH_Name, mName);
	msg->addStringFast(_PREHASH_Description, mDescription);
	msg->addS32Fast(_PREHASH_CreationDate, mCreationDate);
	U32 crc = getCRC32();
	msg->addU32Fast(_PREHASH_CRC, crc);
}
Example #7
0
bool saveHighscoreToFile()
{
	String filename = String(sgLevel.filename) + EXT_HIGHSCORE;
	FILE* file = fopen(filename, "wt");

	if (!file)
	{
		return false;
	}

	/* version number */
	fprintf(file, "v%u\n", THIS_HIGHSCORE_VERSION);

	fprintf(file, "%08X\n", sgLevel.crc32);

	setCRC32(sgLevel.crc32);

	writeByte(file, sgLevel.cntScoreCols);

	fputc('\n', file);

	for (int i = 0; i < sgLevel.cntScoreCols; i++)
	{
		writeInt(file, sgLevel.scores[i].tenthSecond);
		fputc(' ', file);
		writeString(file, sgLevel.scores[i].name);
		fputc('\n', file);
	}

	fprintf(file, "%08X\n", getCRC32());

	if (fclose(file) != 0)
	{
		return false;
	}

	return true;
}
Example #8
0
bool loadLevelFromFile(const char* filename)
{
	FILE* file = fopen(filename, "rt");

	unsigned int version;
	unsigned int crc32;

	sgLevel.filename = filename;

	if (!file)
	{
		if (between(sgLevel.size.x, 1, MAX_LEVEL_SIZE)
				&& between(sgLevel.size.y, 1, MAX_LEVEL_SIZE))
		{
			newLevel();
			return true;
		}
		else
		{
			fprintf(stderr, "can not open file: %s\n", filename);
			return false;
		}
	}

	/* version number */
	if (fscanf(file, "v%u", &version) != 1 || version > THIS_CGM_VERSION)
	{
		fprintf(stderr, "incompatible version number: %u\n", version);
		fclose(file);
		return false;
	}

	resetCRC32();

	/* read attributes */
	readFieldCoord(file, sgLevel.start);
	readFieldCoord(file, sgLevel.finish);
	readFieldCoord(file, sgLevel.size);

	if (version >= 4)
	{
		readString(file, sgLevel.author);
	}

	initLevel();

	/* reading data */
	if (version >= 4)
	{
		int countBlocks = readInt(file);

		for (int i = 0; i < countBlocks; ++i)
		{
			KdCell::Range range;
			int x;
			int y;

			{
				Block b;

				readFieldBlock(file, b);
				b.dirty = true;

				x = b.x;
				y = b.y;

				range.start = sgLevel.blocks.insert(b);
			}
			range.end = range.start + 1;

			sgLevel.kdLevelTree->get(x, y) = range;
		}
	}
	else
	{
		for (int x = 0; x < sgLevel.size.x; x++)
		{
			for (int y = 0; y < sgLevel.size.y; y++)
			{
				KdCell::Range& range = sgLevel.kdLevelTree->get(x, y);

				{
					Block b;

					b.x = x;
					b.y = y;
					readFieldBlockV3(file, b);
					b.dirty = true;

					range.start = sgLevel.blocks.insert(b);
				}
				range.end = range.start + 1;
			}
		}
	}

	sgLevel.crc32 = getCRC32();

	initCommon();

	if (version >= 2)
	{
		if (fscanf(file, "%x\n", &crc32) != 1 || crc32 != getCRC32())
		{
			fprintf(stderr, "1st checksum mismatch: %s\n", filename);
			fclose(file);
			return false;
		}

		{
			int cntSubLightMaps = sgAtlas->getCntAllocatedSubLightMaps();

			int index = 0;

			if (version >= 3)
			{
				while (index < cntSubLightMaps)
				{
					int dataInt[SIZEOF_LIGHT_MAP];

					readRLE(file, dataInt);

					toLightMap(index, false, dataInt);

					index++;
				}
			}
			else
			{
				importLightmapV2(file);
			}

			if (fscanf(file, "%x\n", &crc32) != 1 || crc32 != getCRC32())
			{
				fprintf(stderr, "2st checksum mismatch: %s\n", filename);
				fclose(file);
				return false;
			}
		}
	}
	else
	{
		updateLightMap();
	}

	fclose(file);

	if (!loadHighscoreFromFile())
	{
		sgLevel.cntScoreCols = 0;
	}

	sgLevel.saved = true;

	return true;
}
Example #9
0
	fputc('\n', file);

	FOREACH(indices, iter)
	{
		Block b = sgLevel.blocks[*iter];

		if (shrink)
		{
			b.x -= fcMin.x;
			b.y -= fcMin.y;
		}

		writeFieldBlock(file, b);
	}

	fprintf(file, "%08X\n", getCRC32());

	FOREACH(indices, iter)
	{
		Range subatlas = sgLevel.blocks[*iter].subatlas;

		for (int i = subatlas.start; i < subatlas.end; i++)
		{
			GLfloat dataFloat[SIZEOF_LIGHT_MAP];
			int dataInt[SIZEOF_LIGHT_MAP];

			sgAtlas->getSubLightMap(i, dataFloat);

			for (int j = 0; j < SIZEOF_LIGHT_MAP; j++)
			{
				dataInt[j] = (int) (clamp(dataFloat[j], 0.0f, 1.0f) * 255);
Example #10
0
int minizip_zip(const char * lpszzipfilename, 
                      const char * lpszfilename, 
                      const char * lpszpassword,
                      int nmode, int nLevel)
{
  int nret = -1;
  int nstatus = 0;
//  int opt_compress_level = Z_DEFAULT_COMPRESSION;
	if (nLevel != Z_DEFAULT_COMPRESSION && nLevel != Z_BEST_COMPRESSION && nLevel != Z_BEST_SPEED && nLevel !=  Z_NO_COMPRESSION)
	{
		return -10086;	
	} 
	int nzipmode = APPEND_STATUS_CREATE;
	if (nmode ==0)
	{
		nzipmode = APPEND_STATUS_CREATE;
	}
	else
	{
		nzipmode = APPEND_STATUS_ADDINZIP;
	}
  // Create archive zipfilename
  zipFile zf = zipOpen64(lpszzipfilename, nzipmode);
  if (zf == NULL)
  {
    nstatus = ERROR_CREATE_ZIP;
  }

  int size_buf = WRITE_BUFFER_SIZE;
  Bytef* buf = (Bytef*) malloc(size_buf);

  // Get information about the file on disk so we can store it in zip
  zip_fileinfo zi;
  memset(&zi,0x00,sizeof(zip_fileinfo));
  getFileTime(lpszfilename, &zi.tmz_date, &zi.dosDate);

  unsigned long crcFile = 0;
  if (nstatus == ZIP_OK)
  {
    nstatus = getCRC32(lpszfilename, buf, size_buf, &crcFile);
  }

  int zip64 = isLargeFile(lpszfilename);

  // Construct the filename that our file will be stored in the zip as.
  const char *savefilenameinzip = lpszfilename;
  {
    const char *tmpptr = NULL;
    const char *lastslash = 0;

    for (tmpptr = savefilenameinzip; *tmpptr; tmpptr++)
    {
      if (*tmpptr == '\\' || *tmpptr == '/')
      {
        lastslash = tmpptr;
      }
    }
    if (lastslash != NULL)
    {
      savefilenameinzip = lastslash + 1;
    }
  }
	if ((lpszpassword) && (lpszpassword[0] ==0))
	{
		lpszpassword = NULL;
	}
  // Create zip file
  nstatus = zipOpenNewFileInZip3_64(zf, savefilenameinzip, &zi, NULL, 0, NULL, 0, NULL /* comment*/,
                                   Z_DEFLATED, nLevel, 0,
                                   -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, lpszpassword, crcFile, zip64);

  // Add file to zip
  FILE *fin = NULL;
  if (nstatus == ZIP_OK)
  {
    fin = fopen64(lpszfilename, "rb");
    if (fin == NULL)
    {
      nstatus = ERROR_FILE_NOT_FOUND;
    }
  }

  int size_read = 0;
  if (nstatus == ZIP_OK)
  {
    // Read contents of file and write it to zip
    do
    {
      size_read = (int) fread(buf, 1, size_buf, fin);
      if ((size_read < size_buf) && (feof(fin) == 0))
      {
        nstatus = ERROR_WHILE_READ;
      }

      if (size_read > 0)
      {
        nstatus = zipWriteInFileInZip(zf, buf, size_read);
      }
    }
    while ((nstatus == ZIP_OK) && (size_read > 0));
  }

  if (fin)
  {
    fclose(fin);
  }

  if (nstatus >= 0)
  {
    nstatus = zipCloseFileInZip(zf);
  }

  zipClose(zf, NULL);

  // Release memory
  free(buf);

  if (nstatus == UNZ_OK)
  {
    nret = 0;
  }

  return nret;
}