Esempio n. 1
0
Common::String *LureEngine::detectSave(int slotNumber) {
	Common::ReadStream *f = this->_saveFileMan->openForLoading(
		generateSaveName(slotNumber));
	if (f == NULL) return NULL;
	Common::String *result = NULL;

	// Check for header
	char buffer[5];
	f->read(&buffer[0], 5);
	if (memcmp(&buffer[0], "lure", 5) == 0) {
		// Check language version
		uint8 language = f->readByte();
		uint8 version = f->readByte();
		if ((language == getLanguage()) && (version >= LURE_MIN_SAVEGAME_MINOR)) {
			// Read in the savegame title
			char saveName[MAX_DESC_SIZE];
			char *p = saveName;
			int decCtr = MAX_DESC_SIZE - 1;
			while ((decCtr > 0) && ((*p++ = f->readByte()) != 0)) --decCtr;
			*p = '\0';
			result = new Common::String(saveName);
		}
	}

	delete f;
	return result;
}
Esempio n. 2
0
static int readStream(void *context, char *buffer, int len) {
	Common::ReadStream *stream = (Common::ReadStream *) context;
	if (!stream)
		return -1;

	return stream->read(buffer, len);
}
Esempio n. 3
0
static int readStream(void *context, char *buffer, int len) {
	Common::ReadStream *stream = static_cast<Common::ReadStream *>(context);
	if (!stream)
		return -1;

	return stream->read(buffer, len);
}
Esempio n. 4
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();
}
Esempio n. 5
0
bool SavePartVars::read(Common::ReadStream &stream) {
	if (!_header.verify(stream))
		return false;

	if (stream.read(_data, _size) != _size)
		return false;

	return !stream.err();
}
Esempio n. 6
0
void Display::loadFrameBuffer(Common::ReadStream &stream) {
	byte *dst = _frameBuf;
	for (uint j = 0; j < 8; ++j) {
		for (uint i = 0; i < 8; ++i) {
			stream.read(dst, DISPLAY_PITCH);
			dst += DISPLAY_PITCH * 64;
			stream.read(dst, DISPLAY_PITCH);
			dst += DISPLAY_PITCH * 64;
			stream.read(dst, DISPLAY_PITCH);
			stream.readUint32LE();
			stream.readUint32LE();
			dst -= DISPLAY_PITCH * 120;
		}
		dst -= DISPLAY_PITCH * 63;
	}

	if (stream.eos() || stream.err())
		error("Failed to read frame buffer");
}
Esempio n. 7
0
/*-----------------------------------------------------------------------
 * BtPage
 *-----------------------------------------------------------------------*/
void BtPage::readBTree(Common::ReadStream &s) {
	_header._count = s.readUint16LE();
	_header._down = s.readUint16LE();

	if (_header._down == kBtValNone) {
		// Leaf list
		for (int i = 0; i < kBtLeafCount; ++i) {
			s.read(_leaf[i]._key, kBtKeySize);
			_leaf[i]._pos = s.readUint32LE();
			_leaf[i]._size = s.readUint16LE();
		}
	} else {
		// Root index
		for (int i = 0; i < kBtInnerCount; ++i) {
			s.read(_inner[i]._key, kBtKeySize);
			_inner[i]._down = s.readUint16LE();
		}
	}
}
Esempio n. 8
0
Common::String readLAString(Common::ReadStream &ms) {
	int strLength = ms.readUint32LE();
	char* readString = new char[strLength];
	ms.read(readString, strLength);
	
	Common::String retVal(readString);
	delete[] readString;
	
	return retVal;
}
Esempio n. 9
0
bool SaveContainer::read(Common::ReadStream &stream) {
	// Verify the header and get the container's size
	if (!_header.verifyReadSize(stream))
		return false;

	// The part count has to be correct
	if (stream.readUint32LE() != _partCount)
		return false;

	// Iterate over all parts
	for (PartIterator it = _parts.begin(); it != _parts.end(); ++it) {
		// Read the size
		uint32 size = stream.readUint32LE();

		if (stream.err()) {
			clear();
			return false;
		}

		Part *&p = *it;

		delete p;
		// Create a suitable part
		p = new Part(size);
	}

	// Update size
	_header.setSize(calcSize());

	// Iterate over all parts
	for (PartIterator it = _parts.begin(); it != _parts.end(); ++it) {
		Part *&p = *it;

		// Read the part
		if (stream.read(p->data, p->size) != p->size) {
			clear();
			return false;
		}
	}

	return !stream.err();
}
Esempio n. 10
0
bool SavePartInfo::read(Common::ReadStream &stream) {
	if (!_header.verify(stream))
		return false;

	if (stream.readUint32LE() != _gameID)
		return false;
	if (stream.readUint32LE() != _gameVersion)
		return false;
	if (stream.readByte() != _endian)
		return false;
	if (stream.readUint32LE() != _varCount)
		return false;
	if (stream.readUint32LE() != _descMaxLength)
		return false;

	if (stream.read(_desc, _descMaxLength) != _descMaxLength)
		return false;

	_desc[_descMaxLength] = 0;

	return !stream.err();
}
Esempio n. 11
0
bool LureEngine::loadGame(uint8 slotNumber) {
	Common::ReadStream *f = this->_saveFileMan->openForLoading(
		generateSaveName(slotNumber));
	if (f == NULL)
		return false;

	// Check for header
	char buffer[5];
	f->read(buffer, 5);
	if (memcmp(buffer, "lure", 5) != 0) {
		warning(FAILED_MSG, slotNumber);
		delete f;
		return false;
	}

	// Check language version
	uint8 language = f->readByte();
	_saveVersion = f->readByte();
	if ((language != getLureLanguage()) || (_saveVersion < LURE_MIN_SAVEGAME_MINOR)) {
		warning("loadGame: Failed to load slot %d - incorrect version", slotNumber);
		delete f;
		return false;
	}

	// Read in and discard the savegame caption
	while (f->readByte() != 0)
		;

	// Load in the data
	Resources::getReference().loadFromStream(f);
	Game::getReference().loadFromStream(f);
	Sound.loadFromStream(f);
	Fights.loadFromStream(f);
	Room::getReference().loadFromStream(f);

	delete f;
	return true;
}
Esempio n. 12
0
	void operator()(std::array<T, N>& t) const {
		_s->read(t.data(), N * sizeof(T));
	}
Esempio n. 13
0
/**
 * Read a given number of bytes from a Stream into a pre-allocated buffer
 */
int FileManager::readStream(Common::ReadStream &stream, void *buf, size_t nbytes) {
	return stream.read(buf, nbytes);
}