Example #1
0
bool SavePartSprite::read(Common::ReadStream &stream) {
	SaveHeader header;
	header.read(stream);

	if (_header != header) {
		if (!_trueColor) {
			// Header validation failed, trying again with the old version

			_header.setVersion(1);
			_header.setSize(_header.getSize() - 1);

			if (_header != header)
				// Nope, isn't it either
				return false;

			_oldFormat = true;

			_header.setVersion(kVersion);
			_header.setSize(_header.getSize() + 1);

		} else
			return false;
	}

	// The sprite's dimensions have to fit
	if (stream.readUint32LE() != _width)
		return false;
	if (stream.readUint32LE() != _height)
		return false;

	// If it's in the current format, the true color flag has to be the same too
	if (!_oldFormat)
		if ((stream.readByte() != 0) != _trueColor)
			return false;

	// Sprite data
	if (stream.read(_dataSprite, _spriteSize) != _spriteSize)
		return false;

	// Palette data
	if (stream.read(_dataPalette, 768) != 768)
		return false;

	return !stream.err();
}
Example #2
0
Common::Array<SaveContainer::PartInfo> *SaveContainer::getPartsInfo(Common::SeekableReadStream &stream) {
	Common::Array<PartInfo> *parts = 0;

	// Remember the stream's position to seek back to
	uint32 startPos = stream.pos();

	SaveHeader header;

	header.setType(kID);
	header.setVersion(kVersion);

	// Verify the header
	if (!header.verifyReadSize(stream)) {
		// Seek back
		stream.seek(startPos);
		return 0;
	}

	// Read the part count
	uint32 partCount = stream.readUint32LE();

	// Create a part information array
	parts = new Common::Array<PartInfo>;
	parts->resize(partCount);

	// Read all part sizes
	for (uint32 i = 0; i < partCount; i++)
		(*parts)[i].size = stream.readUint32LE();

	// Iterate over all parts
	for (uint32 i = 0; i < partCount; i++) {
		// The part's offset (from the starting point of the stream)
		(*parts)[i].offset = stream.pos() - startPos;

		SaveHeader partHeader;

		// Read the header
		if (!partHeader.read(stream)) {
			// Seek back
			stream.seek(startPos);
			delete parts;
			return 0;
		}

		// Fill in the ID
		(*parts)[i].id = partHeader.getType();

		// Skip the part's content
		stream.skip(partHeader.getSize());
	}

	if (stream.err()) {
		delete parts;
		parts = 0;
	}

	// Seek back
	stream.seek(startPos);

	return parts;
}