Exemplo n.º 1
0
CDialog::DIALOGTEMPLATE CDialog::ReadDialogTemplate(Framework::CStream& stream)
{
	DIALOGTEMPLATE dialog;

	dialog.dlgVer		= stream.Read16();
	dialog.signature	= stream.Read16();

	assert(dialog.dlgVer == 1);
	assert(dialog.signature == 0xFFFF);

	dialog.helpID		= stream.Read32();
	dialog.exStyle		= stream.Read32();
	dialog.style		= stream.Read32();
	dialog.cDlgItems	= stream.Read16();
	dialog.x			= stream.Read16();
	dialog.y			= stream.Read16();
	dialog.cx			= stream.Read16();
	dialog.cy			= stream.Read16();
	
	assert((stream.Tell() & 0x01) == 0);
	dialog.menu			= ReadSzOrOrd(stream);
	
	assert((stream.Tell() & 0x01) == 0);
	dialog.windowClass	= ReadSzOrOrd(stream);
	
	assert((stream.Tell() & 0x01) == 0);
	dialog.title		= ReadString(stream);
	
	dialog.pointsize	= stream.Read16();
	dialog.weight		= stream.Read16();
	dialog.italic		= stream.Read8();
	dialog.charset		= stream.Read8();

	assert((stream.Tell() & 0x01) == 0);
	dialog.typeface		= ReadString(stream);

	//Struct has padding for alignment to DWORD boundary (only if there's other items to read)
	if(stream.GetRemainingLength() != 0)
	{
		auto currentBytePos = stream.Tell() & 0x3;
		if(currentBytePos != 0)
		{
			stream.Seek(4 - currentBytePos, Framework::STREAM_SEEK_CUR);
		}
		assert((stream.Tell() & 0x03) == 0);
	}

	uint32 itemDataLength = static_cast<uint32>(stream.GetRemainingLength());
	if(itemDataLength != 0)
	{
		dialog.dialogItemData.resize(itemDataLength);
		stream.Read(&dialog.dialogItemData[0], itemDataLength);
	}

	return dialog;
}
Exemplo n.º 2
0
void CPwibSection::Read(Framework::CStream& inputStream)
{
	uint32 signature = inputStream.Read32();
	assert(signature == 'BIWP');
	uint32 fileSize = inputStream.Read32_MSBF();
	uint32 unknown = inputStream.Read32_MSBF();
	m_dataOffset = inputStream.Read32_MSBF();
	auto child = CSectionLoader::ReadSection(shared_from_this(), inputStream);
}
Exemplo n.º 3
0
CBspFile::CBspFile(Framework::CStream& inputStream)
{
	uint8 signature[4];
	inputStream.Read(signature, 4);
	if(memcmp(signature, "IBSP", 4))
	{
		throw std::runtime_error("Invalid BSP. Bad signature.");
	}
	
	uint32 version = inputStream.Read32();
	assert(version == 0x2E);

	DIRENTRY dirEntries[DIRENTRY_COUNT];
	for(unsigned int i = 0; i < DIRENTRY_COUNT; i++)
	{
		dirEntries[i].offset = inputStream.Read32();
		dirEntries[i].length = inputStream.Read32();
	}

	ReadLumpData(inputStream, dirEntries[LUMP_ENTITIES], m_entities);
	ReadLumpData(inputStream, dirEntries[LUMP_PLANES], m_planes);
	ReadLumpData(inputStream, dirEntries[LUMP_NODES], m_nodes);
	ReadLumpData(inputStream, dirEntries[LUMP_LEAVES], m_leaves);
	ReadLumpData(inputStream, dirEntries[LUMP_LEAFFACES], m_leafFaces);
	ReadLumpData(inputStream, dirEntries[LUMP_TEXTURES], m_textures);
	ReadLumpData(inputStream, dirEntries[LUMP_VERTICES], m_vertices);
	ReadLumpData(inputStream, dirEntries[LUMP_MESHVERTICES], m_meshVertices);
	ReadLumpData(inputStream, dirEntries[LUMP_EFFECTS], m_effects);
	ReadLumpData(inputStream, dirEntries[LUMP_FACES], m_faces);
	ReadLumpData(inputStream, dirEntries[LUMP_LIGHTMAPS], m_lightMaps);

	//Read VISDATA
	{
		inputStream.Seek(dirEntries[LUMP_VISDATA].offset, Framework::STREAM_SEEK_SET);
		m_visData.vectorCount = inputStream.Read32();
		m_visData.vectorSize = inputStream.Read32();
		uint32 visDataSize = m_visData.vectorCount * m_visData.vectorSize;
		m_visData.vectors.resize(visDataSize);
		inputStream.Read(&m_visData.vectors[0], visDataSize);
	}
}
Exemplo n.º 4
0
CPathTableRecord::CPathTableRecord(Framework::CStream& stream)
{
	m_nameLength = stream.Read8();
	m_exLength = stream.Read8();
	m_location = stream.Read32();
	m_parentDir = stream.Read16();
	m_directory = stream.ReadString(m_nameLength);

	if(m_nameLength & 1)
	{
		stream.Seek(1, Framework::STREAM_SEEK_CUR);
	}
}
Exemplo n.º 5
0
void CDdsImage::Read(Framework::CStream& inputStream)
{
	uint32 signature = inputStream.Read32();
	if(signature != ' SDD')
	{
		assert(0);
		throw std::runtime_error("Invalid DDS image (Invalid signature).");
	}

	inputStream.Read(&m_header, sizeof(DDS_HEADER));
	if(m_header.size != sizeof(DDS_HEADER))
	{
		assert(0);
		throw std::runtime_error("Invalid DDS image (Invalid header size).");
	}

	if(m_header.ddspf.size != sizeof(DDS_PIXELFORMAT))
	{
		assert(0);
		throw std::runtime_error("Invalid DDS image (Invalid header size).");
	}

	const uint32 mandatoryFlags = DDS_HEADER_FLAG_CAPS | DDS_HEADER_FLAG_HEIGHT | DDS_HEADER_FLAG_WIDTH | DDS_HEADER_FLAG_PIXELFORMAT;
	if((m_header.flags & mandatoryFlags) != mandatoryFlags)
	{
		assert(0);
		throw std::runtime_error("Invalid DDS image (Missing flags).");
	}

	assert((m_header.ddspf.flags & (DDS_PIXELFORMAT_FLAG_RGB | DDS_PIXELFORMAT_FLAG_ALPHAPIXELS)) != 0);

	uint32 surfaceSize = (m_header.ddspf.rgbBitCount / 8) * m_header.width * m_header.height;

	if(m_header.caps2 & DDS_HEADER_CAP2_CUBEMAP)
	{
		const uint32 fullCubeMapFlags = 
			DDS_HEADER_CAP2_CUBEMAP_POSITIVE_X | DDS_HEADER_CAP2_CUBEMAP_NEGATIVE_X |
			DDS_HEADER_CAP2_CUBEMAP_POSITIVE_Y | DDS_HEADER_CAP2_CUBEMAP_NEGATIVE_Y |
			DDS_HEADER_CAP2_CUBEMAP_POSITIVE_Z | DDS_HEADER_CAP2_CUBEMAP_NEGATIVE_Z;
		assert((m_header.caps2 & fullCubeMapFlags) == fullCubeMapFlags);

		for(unsigned int i = 0; i < 6; i++)
		{
			SurfaceByteArray surface(surfaceSize);
			inputStream.Read(surface.data(), surfaceSize);
			m_surfaces.push_back(std::move(surface));
		}
	}
}
Exemplo n.º 6
0
void CPatchFile::ExecuteETRY(Framework::CStream& inputStream)
{
	uint32 pathSize = inputStream.Read32_MSBF();
	std::vector<char> pathData(pathSize);
	inputStream.Read(pathData.data(), pathSize);
	std::string path(std::begin(pathData), std::end(pathData));

	auto fullFilePath = m_gameLocationPath / path;
	auto fullFileDirectory = fullFilePath;
	fullFileDirectory.remove_leaf();
	fullFileDirectory.make_preferred();
	fullFilePath.make_preferred();

	if(!boost::filesystem::exists(fullFileDirectory))
	{
		m_result.messages.push_back(string_format("Warning: Directory '%s' doesn't exist. Creating.", 
			fullFileDirectory.string().c_str()
		));
		boost::filesystem::create_directories(fullFileDirectory);
	}

	if(!boost::filesystem::exists(fullFilePath))
	{
		m_result.messages.push_back(string_format("Warning: File '%s' doesn't exist. Creating.", fullFilePath.string().c_str()));
	}

	uint32 itemCount = inputStream.Read32_MSBF();
	for(unsigned int i = 0; i < itemCount; i++)
	{
		//0x41 = last hash, 0x44 = first hash, 0x4D = both hashes?
		uint32 hashMode = inputStream.Read32();
		assert(hashMode == 0x41 || hashMode == 0x44 || hashMode == 0x4D);

		uint8 srcFileHash[0x14];
		uint8 dstFileHash[0x14];
		inputStream.Read(srcFileHash, sizeof(srcFileHash));
		inputStream.Read(dstFileHash, sizeof(dstFileHash));

		//4E is no compression
		//5A is zlib compression
		uint32 compressionMode = inputStream.Read32();
		assert((compressionMode == 0x4E) || (compressionMode == 0x5A));

		uint32 compressedFileSize = inputStream.Read32_MSBF();
		uint32 previousFileSize = inputStream.Read32_MSBF();
		uint32 newFileSize = inputStream.Read32_MSBF();

		if(i != (itemCount - 1))
		{
			assert(compressedFileSize == 0);
		}
		if(compressedFileSize == 0) continue;

		//Data starts here
		{
			//Retrying here because explorer.exe can sometimes open the ffxiv*.exe files to load
			//the icons making the open operation fail if we need to patch it again.
			
			auto outputStream = CreateOutputStdStreamWithRetry(fullFilePath.native());
			if(compressionMode == 0x4E)
			{
				ExtractUncompressed(outputStream, inputStream, compressedFileSize);
			}
			else if(compressionMode == 0x5A)
			{
				ExtractCompressed(outputStream, inputStream, compressedFileSize);
			}
			else
			{
				throw std::runtime_error("Unknown compression type.");
			}
		}
	}

	inputStream.Seek(0x08, Framework::STREAM_SEEK_CUR);
}