Beispiel #1
0
uint32 CIoman::Seek(uint32 handle, uint32 position, uint32 whence)
{
	CLog::GetInstance().Print(LOG_NAME, "Seek(handle = %d, position = 0x%X, whence = %d);\r\n", 
		handle, position, whence);

	uint32 result = 0xFFFFFFFF;
	try
	{
		Framework::CStream* stream = GetFileStream(handle);
		switch(whence)
		{
		case SEEK_DIR_SET:
			whence = Framework::STREAM_SEEK_SET;
			break;
		case SEEK_DIR_CUR:
			whence = Framework::STREAM_SEEK_CUR;
			break;
		case SEEK_DIR_END:
			whence = Framework::STREAM_SEEK_END;
			break;
		}

		stream->Seek(position, static_cast<Framework::STREAM_SEEK_DIRECTION>(whence));
		result = static_cast<uint32>(stream->Tell());
	}
	catch(const std::exception& except)
	{
		CLog::GetInstance().Print(LOG_NAME, "%s: Error occured while trying to seek file : %s\r\n", __FUNCTION__, except.what());
	}
	return result;
}
Beispiel #2
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;
}
void CContainerChunk::LoadChildren(Framework::CStream& inputStream)
{
	for(uint32 i = 0; i < m_childrenCount; i++)
	{
		uint64 baseOffset = inputStream.Tell();
		auto chunk = CChunkLoader::Load(shared_from_this(), inputStream);
		AddChild(chunk);
		uint64 nextOffset = baseOffset + chunk->GetNextChunkOffset();
		inputStream.Seek(nextOffset, Framework::STREAM_SEEK_SET);
	}
}
Beispiel #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);
	}
}
Beispiel #5
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);
	}
}
Beispiel #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);
}
void CResourceSection::Read(Framework::CStream& inputStream)
{
	CBaseSection::Read(inputStream);

	SEDBRES_HEADER header = {};
	inputStream.Read(&header, sizeof(SEDBRES_HEADER));

	std::vector<SEDBRES_ENTRY> entries;
	entries.resize(header.resourceCount);
	inputStream.Read(entries.data(), header.resourceCount * sizeof(SEDBRES_ENTRY));

	uint64 basePosition = inputStream.Tell();

	assert(header.resourceCount >= 2);

	const auto& resourceTypeEntry = entries[header.resourceCount - 2];
	const auto& resourceIdEntry = entries[header.resourceCount - 1];

	std::vector<uint32> resourceTypes;
	resourceTypes.resize(header.resourceCount);
	inputStream.Seek(basePosition + resourceTypeEntry.offset, Framework::STREAM_SEEK_SET);
	inputStream.Read(resourceTypes.data(), sizeof(uint32) * header.resourceCount);

	//Read resource ids
	std::vector<std::string> resourceIds;
	for(unsigned int i = 0; i < header.resourceCount; i++)
	{
		inputStream.Seek(basePosition + resourceIdEntry.offset + (i * 0x10), Framework::STREAM_SEEK_SET);
		resourceIds.push_back(inputStream.ReadString());
	}

	//Read string table
	inputStream.Seek(basePosition + header.stringsOffset, Framework::STREAM_SEEK_SET);
	std::vector<std::string> strings;
	for(unsigned int i = 0; i < header.stringCount; i++)
	{
		strings.push_back(inputStream.ReadString());
	}

	for(unsigned int i = 0; i < header.resourceCount; i++)
	{
		const auto& entry = entries[i];
		if(entry.type == 0 || entry.size == 0) continue;
		uint32 resourceType = resourceTypes[i];
		inputStream.Seek(basePosition + entry.offset, Framework::STREAM_SEEK_SET);
		SectionPtr section;
		switch(resourceType)
		{
		case '\0trb':
		case '\0bin':
			section = std::make_shared<CResourceSection>();
			break;
		case 'sdrb':
			section = std::make_shared<CShaderSection>();
			break;
		case '\0wrb':
			section = std::make_shared<CModelSection>();
			break;
		case '\0skl':
			section = std::make_shared<CSkeletonSection>();
			break;
		case '\0phb':
			section = std::make_shared<CPhbSection>();
			break;
		case '\0txb':
			section = std::make_shared<CTextureSection>();
			break;
		default:
			assert(0);
			break;
		}
		if(section)
		{
			AddChild(section);
			section->Read(inputStream);
			section->SetResourceId(resourceIds[i]);
			section->SetResourcePath(strings[i]);
		}
	}

	inputStream.Seek(basePosition, Framework::STREAM_SEEK_SET);
}