Ejemplo n.º 1
0
void BIFFile::readVarResTable(Common::SeekableReadStream &bif, uint32 offset) {
	bif.seek(offset);

	for (IResourceList::iterator res = _iResources.begin(); res != _iResources.end(); ++res) {
		bif.skip(4); // ID

		if (_version == kVersion11)
			bif.skip(4); // Flags

		res->offset = bif.readUint32LE();
		res->size   = bif.readUint32LE();
		res->type   = (FileType) bif.readUint32LE();
	}
}
Ejemplo n.º 2
0
void TGA::readHeader(Common::SeekableReadStream &tga, ImageType &imageType, byte &pixelDepth, byte &imageDesc) {
	tga.seek(0);

	// TGAs have an optional "id" string in the header
	uint32 idLength = tga.readByte();

	// Number of colors in the color map / palette
	if (tga.readByte() != 0)
		throw Common::Exception("Unsupported feature: Color map");

	// Image type. 2 == unmapped RGB, 3 == Grayscale
	imageType = (ImageType)tga.readByte();
	if (!isSupportedImageType(imageType))
		throw Common::Exception("Unsupported image type: %d", imageType);

	// Color map specifications + X + Y
	tga.skip(5 + 2 + 2);

	_mipMaps.push_back(new MipMap);

	// Image dimensions
	_mipMaps[0]->width  = tga.readUint16LE();
	_mipMaps[0]->height = tga.readUint16LE();

	// Bits per pixel
	pixelDepth = tga.readByte();

	if (imageType == kImageTypeTrueColor || imageType == kImageTypeRLETrueColor) {
		if (pixelDepth == 24) {
			_format = kPixelFormatB8G8R8;
		} else if (pixelDepth == 16 || pixelDepth == 32) {
			_format = kPixelFormatB8G8R8A8;
		} else if (pixelDepth == 8) {
			imageType = kImageTypeBW;
			_format = kPixelFormatB8G8R8A8;
		} else
			throw Common::Exception("Unsupported pixel depth: %d, %d", imageType, pixelDepth);
	} else if (imageType == kImageTypeBW) {
		if (pixelDepth != 8)
			throw Common::Exception("Unsupported pixel depth: %d, %d", imageType, pixelDepth);

		_format = kPixelFormatB8G8R8A8;
	}

	// Image descriptor
	imageDesc = tga.readByte();

	// Skip the id string
	tga.skip(idLength);
}
Ejemplo n.º 3
0
void Map_v1::loadItemToObject(Common::SeekableReadStream &data) {
	int16 count;

	if (data.readUint16LE() == 0)
		return;

	data.skip(1456);
	count = data.readUint16LE();
	for (int i = 0; i < count; i++) {
		data.skip(20);
		_vm->_goblin->_itemToObject[i] = data.readUint16LE();
		data.skip(5);
	}
}
Ejemplo n.º 4
0
void NewFeature::resetScript() {
	// FIXME: registrations, etc
	Common::SeekableReadStream *ourSCRB = _view->getSCRB(_data.scrbIndex, _scrbId);
	ourSCRB->seek(16);
	Common::Point scriptBase, scriptSize;
	scriptBase.x = ourSCRB->readUint16BE();
	scriptBase.y = ourSCRB->readUint16BE();
	scriptSize.x = ourSCRB->readUint16BE();
	scriptSize.y = ourSCRB->readUint16BE();
	ourSCRB->seek(26);
	Common::Point one, two;
	while (true) {
		if (ourSCRB->pos() == ourSCRB->size())
			error("resetScript (getNewXYAndReg) ran out of script");
		byte opcode = ourSCRB->readByte();
		byte size = ourSCRB->readByte();
		if (opcode != 0x10) {
			ourSCRB->skip(size - 2);
		} else if (size) {
			assert(size >= 1);
			ourSCRB->skip(2);
			int16 x = ourSCRB->readUint16BE();
			int16 y = ourSCRB->readUint16BE();
			one.x = -x;
			one.y = -y;
			two.x = scriptBase.x + x;
			two.y = scriptBase.y + y;
			break;
		}
	}
	delete ourSCRB;

	if ((_needsReset || false /* TODO: param */) && (_unknown168 == 0x7FFFFFFF || false /* TODO: param */)) {
		_data.currentPos = two;
		_data.nextPos = one;
		_unknown168 = 0;
		if (_needsReset || false /* TODO: param */) {
			_data.bounds = Common::Rect(scriptBase.x, scriptBase.y, scriptSize.x, scriptSize.y);
		}
	} else {
		if (false /* FIXME: 0 shapes? */) {
			_data.nextPos.x = one.x + two.x - _data.currentPos.x;
			_data.nextPos.y = one.y + two.y - _data.currentPos.y;
		} else if (_unknown168 != 0x7FFFFFFF) {
			_data.nextPos = one;
		}
	}
	// _needsReset = 0; (handled by caller)
}
Ejemplo n.º 5
0
void HERFFile::load() {
	Common::SeekableReadStream *herf = ResMan.getResource(TypeMan.setFileType(_fileName, kFileTypeNone), kFileTypeHERF);
	if (!herf)
		throw Common::Exception(Common::kOpenError);

	herf->skip(4);
	uint32 resCount = herf->readUint32LE();

	_resources.resize(resCount);
	_iResources.resize(resCount);

	try {

		readResList(*herf);

	if (herf->err())
		throw Common::Exception(Common::kReadError);

	} catch (Common::Exception &e) {
		delete herf;
		e.add("Failed reading HERF file");
		throw e;
	}

	delete herf;
}
Ejemplo n.º 6
0
void RIMFile::load(Common::SeekableReadStream &rim) {
	readHeader(rim);

	if (_id != kRIMID)
		throw Common::Exception("Not a RIM file (%s)", Common::debugTag(_id).c_str());

	if (_version != kVersion1)
		throw Common::Exception("Unsupported RIM file version %s", Common::debugTag(_version).c_str());

	rim.skip(4);                            // Reserved
	uint32 resCount   = rim.readUint32LE(); // Number of resources in the RIM
	uint32 offResList = rim.readUint32LE(); // Offset to the resource list

	_resources.resize(resCount);
	_iResources.resize(resCount);

	try {

		// Read the resource list
		readResList(rim, offResList);

	} catch (Common::Exception &e) {
		e.add("Failed reading RIM file");
		throw;
	}

}
Ejemplo n.º 7
0
void XEOSITEX::readHeader(Common::SeekableReadStream &xeositex) {
    const uint32 magic1 = xeositex.readUint32BE();
    const uint32 magic2 = xeositex.readUint32BE();
    if ((magic1 != kXEOSID) || (magic2 != kITEXID))
        throw Common::Exception("Not a valid XEOSITEX (%s, %s)",
                                Common::debugTag(magic1).c_str(), Common::debugTag(magic2).c_str());

    const uint32 version = xeositex.readUint32LE();
    if (version != 0)
        throw Common::Exception("Invalid XEOSITEX version %u", version);

    const uint32 pixelFormat = xeositex.readUint32LE();
    if ((pixelFormat != 3) && (pixelFormat != 4))
        throw Common::Exception("Invalid XEOSITEX pixel format %u", pixelFormat);

    if      (pixelFormat == 3)
        _format = kPixelFormatB8G8R8;
    else if (pixelFormat == 4)
        _format = kPixelFormatB8G8R8A8;

    _wrapX = xeositex.readByte() != 0;
    _wrapY = xeositex.readByte() != 0;
    _flipX = xeositex.readByte() != 0;
    _flipY = xeositex.readByte() != 0;

    _coordTransform = xeositex.readByte();

    xeositex.skip(1); // Filter

    const uint32 mipMaps = xeositex.readUint32LE();
    _mipMaps.resize(mipMaps, 0);
}
Ejemplo n.º 8
0
void ActorType::load(byte *dataStart, Common::SeekableReadStream &stream) {
	_actorTypeId = stream.readUint32LE();
	_surfInfo.load(stream);
	uint32 pointsConfigOffs = stream.readUint32LE();
	uint namedPointsCount = stream.readUint16LE();
	stream.skip(2); // Skip padding
	uint32 namedPointsOffs = stream.readUint32LE();
	_color.r = stream.readByte();
	_color.g = stream.readByte();
	_color.b = stream.readByte();
	stream.readByte(); // Skip padding
	_scale = stream.readByte();
	_priority = stream.readByte();
	_value1E = stream.readUint16LE();
	_pathWalkPointsIndex = stream.readUint16LE();
	_scaleLayerIndex = stream.readUint16LE();
	_pathWalkRectIndex = stream.readUint16LE();
	_priorityLayerIndex = stream.readUint16LE();
	_regionLayerIndex = stream.readUint16LE();
	_flags = stream.readUint16LE();
	_pointsConfig = dataStart + pointsConfigOffs;
	stream.seek(namedPointsOffs);
	_namedPoints.load(namedPointsCount, stream);
	debug(5, "ActorType::load() _actorTypeId: %08X; _color(%d,%d,%d); _scale: %d; _priority: %d; _value1E: %d",
		_actorTypeId, _color.r, _color.g, _color.b, _scale, _priority, _value1E);
	debug(5, "ActorType::load() _pathWalkPointsIndex: %d; _scaleLayerIndex: %d; _pathWalkRectIndex: %d",
		_pathWalkPointsIndex, _scaleLayerIndex, _pathWalkRectIndex);
	debug(5, "ActorType::load() _priorityLayerIndex: %d; _regionLayerIndex: %d; _flags: %04X",
		_priorityLayerIndex, _regionLayerIndex,_flags);
}
Ejemplo n.º 9
0
static Common::UString readStringQuoting(Common::SeekableReadStream &ncs, size_t length) {
	Common::UString str;

	while (length-- > 0) {
		byte c = ncs.readByte();
		if (!c)
			break;

		if      (c == '\n')
			str += "\\n";
		else if (c == '\r')
			str += "\\r";
		else if (c == '\t')
			str += "\\t";
		else if (c == '\"')
			str += "\\\"";
		else if (c == '\\')
			str += "\\\\";
		else if (c < 32 || c > 126)
			str += Common::UString::format("\\x%02X", c);
		else
			str += (uint32) c;
	}

	if (length != SIZE_MAX)
		ncs.skip(length);

	return str;
}
Ejemplo n.º 10
0
void HERFFile::getDictionary(std::list<uint32> &hashes, std::list<Common::UString> &names) const {
	hashes.clear();
	names.clear();

	if (_dictIndex == 0xFFFFFFFF)
		return;

	Common::SeekableReadStream *dict = getResource(_dictIndex);

	dict->skip(8); // unknown

	while (dict->pos() < dict->size()) {
		uint32 hash = dict->readUint32LE();
		if (hash == 0)
			break;

		hashes.push_back(hash);
		names.push_back("");

		names.back().readFixedASCII(*dict, 128);
		names.back().tolower();
	}

	delete dict;
}
Ejemplo n.º 11
0
void Walkmesh::appendFromStream(Common::SeekableReadStream &stream) {
	stream.seek(0);

	/** Header format:
	 *
	 *  uint8[8]  - WOK version
	 *  uint32    - walkmesh type
	 *  uint8[48] - reserved
	 *  float[3]  - position
	 */

	if (stream.readUint32BE() != MKTAG('B', 'W', 'M', ' ') ||
			stream.readUint32BE() != MKTAG('V', '1', '.', '0'))
		throw Common::Exception("Invalid WOK version");

	stream.skip(64);

	uint32 vertexCount = stream.readUint32LE();
	uint32 vertexOffset = stream.readUint32LE();
	uint32 faceCount = stream.readUint32LE();
	uint32 faceOffset = stream.readUint32LE();
	uint32 faceTypeOffset = stream.readUint32LE();

	//-

	appendFaceTypes(stream, faceCount, faceTypeOffset);
	appendIndices(stream, faceCount, faceOffset);
	appendVertices(stream, vertexCount, vertexOffset);
}
Ejemplo n.º 12
0
void ASFStream::parseStreamHeader() {
	ASFGUID guid = ASFGUID(*_stream);

	if (guid != s_asfAudioStream)
		throw Common::Exception("ASFStream::parseStreamHeader(): Found non-audio stream");

	_stream->skip(16); // skip a guid
	_stream->readUint64LE(); // total size
	uint32 typeSpecificSize = _stream->readUint32LE();
	_stream->readUint32LE();
	_streamID = _stream->readUint16LE();
	_stream->readUint32LE();

	// Parse the wave header
	_compression = _stream->readUint16LE();
	_channels = _stream->readUint16LE();
	_sampleRate = _stream->readUint32LE();
	_bitRate = _stream->readUint32LE() * 8;
	_blockAlign = _stream->readUint16LE();
	_bitsPerCodedSample = (typeSpecificSize == 14) ? 8 : _stream->readUint16LE();

	if (typeSpecificSize >= 18) {
		uint32 cbSize = _stream->readUint16LE();
		cbSize = MIN<int>(cbSize, typeSpecificSize - 18);
		_extraData = _stream->readStream(cbSize);
	}

	_codec = createCodec();
}
Ejemplo n.º 13
0
Common::SeekableReadStream *QuickTimeDecoder::VideoTrackHandler::getNextFramePacket(uint32 &descId) {
	// First, we have to track down which chunk holds the sample and which sample in the chunk contains the frame we are looking for.
	int32 totalSampleCount = 0;
	int32 sampleInChunk = 0;
	int32 actualChunk = -1;
	uint32 sampleToChunkIndex = 0;

	for (uint32 i = 0; i < _parent->chunkCount; i++) {
		if (sampleToChunkIndex < _parent->sampleToChunkCount && i >= _parent->sampleToChunk[sampleToChunkIndex].first)
			sampleToChunkIndex++;

		totalSampleCount += _parent->sampleToChunk[sampleToChunkIndex - 1].count;

		if (totalSampleCount > _curFrame) {
			actualChunk = i;
			descId = _parent->sampleToChunk[sampleToChunkIndex - 1].id;
			sampleInChunk = _parent->sampleToChunk[sampleToChunkIndex - 1].count - totalSampleCount + _curFrame;
			break;
		}
	}

	if (actualChunk < 0) {
		warning("Could not find data for frame %d", _curFrame);
		return 0;
	}

	// Next seek to that frame
	Common::SeekableReadStream *stream = _decoder->_fd;
	stream->seek(_parent->chunkOffsets[actualChunk]);

	// Then, if the chunk holds more than one frame, seek to where the frame we want is located
	for (int32 i = _curFrame - sampleInChunk; i < _curFrame; i++) {
		if (_parent->sampleSize != 0)
			stream->skip(_parent->sampleSize);
		else
			stream->skip(_parent->sampleSizes[i]);
	}

	// Finally, read in the raw data for the frame
	//debug("Frame Data[%d]: Offset = %d, Size = %d", _curFrame, stream->pos(), _parent->sampleSizes[_curFrame]);

	if (_parent->sampleSize != 0)
		return stream->readStream(_parent->sampleSize);

	return stream->readStream(_parent->sampleSizes[_curFrame]);
}
Ejemplo n.º 14
0
bool Resources::loadArchives(const ADGameDescription *gd) {
	Common::File *dat_file = new Common::File();
	Common::String filename = "teenagent.dat";
	if (!dat_file->open(filename.c_str())) {
		delete dat_file;
		Common::String errorMessage = Common::String::format(_("Unable to locate the '%s' engine data file."), filename.c_str());
		warning("%s", errorMessage.c_str());
		GUIErrorMessage(errorMessage);
		return false;
	}

	// teenagent.dat used to be compressed with zlib compression. The usage of
	// zlib here is no longer needed, and it's maintained only for backwards
	// compatibility.
	Common::SeekableReadStream *dat = Common::wrapCompressedReadStream(dat_file);

#if !defined(USE_ZLIB)
	uint16 header = dat->readUint16BE();
	bool isCompressed = (header == 0x1F8B ||
				     ((header & 0x0F00) == 0x0800 &&
				      header % 31 == 0));
	dat->seek(-2, SEEK_CUR);

	if (isCompressed) {
		// teenagent.dat is compressed, but zlib hasn't been compiled in
		delete dat;
		Common::String errorMessage = _("The teenagent.dat file is compressed and zlib hasn't been included in this executable. Please decompress it");
		warning("%s", errorMessage.c_str());
		GUIErrorMessage(errorMessage);
		return false;
	}
#endif

	dat->skip(CSEG_SIZE);
	dseg.read(dat, DSEG_SIZE);
	eseg.read(dat, ESEG_SIZE);
	delete dat;

	precomputeDialogOffsets();

	FilePack varia;
	varia.open("varia.res");
	font7.load(varia, 7, 11, 1);
	font8.load(varia, 8, 31, 0);
	varia.close();

	off.open("off.res");
	on.open("on.res");
	ons.open("ons.res");
	lan000.open("lan_000.res");
	lan500.open("lan_500.res");
	mmm.open("mmm.res");
	sam_mmm.open("sam_mmm.res");
	sam_sam.open("sam_sam.res");
	voices.open("voices.res");

	return true;
}
Ejemplo n.º 15
0
bool NDSFile::readHeader(Common::SeekableReadStream &nds) {
	nds.seek(0x00);
	_name.readFixedASCII(nds, 12);
	_code.readFixedASCII(nds, 4);
	_maker.readFixedASCII(nds, 2);

	nds.seek(0x20);
	_arm9CodeOffset = nds.readUint32LE();
	nds.skip(8);
	_arm9CodeSize = nds.readUint32LE();

	nds.seek(0x30);
	_arm7CodeOffset = nds.readUint32LE();
	nds.skip(8);
	_arm7CodeSize = nds.readUint32LE();

	nds.seek(0x40);
	_fileNameTableOffset = nds.readUint32LE();
	_fileNameTableLength = nds.readUint32LE();
	_fatOffset           = nds.readUint32LE();
	_fatLength           = nds.readUint32LE();

	nds.seek(0x80);
	_romSize    = nds.readUint32LE();
	_headerSize = nds.readUint32LE();

	const uint32 size = nds.size();

	if ((_fileNameTableOffset >= size) || ((_fileNameTableOffset + _fileNameTableLength) > size))
		return false;
	if ((_fatOffset >= size) || ((_fatOffset + _fatLength) > size))
		return false;

	if ((_arm9CodeOffset >= size) || ((_arm9CodeOffset + _arm9CodeSize) > size))
		return false;
	if ((_arm7CodeOffset >= size) || ((_arm7CodeOffset + _arm7CodeSize) > size))
		return false;

	if (_romSize > size)
		return false;
	if (_headerSize > size)
		return false;

	return true;
}
Ejemplo n.º 16
0
static bool isBigEndian(Common::SeekableReadStream &stream) {
	stream.skip(4); // Tag, we don't care about that one here

	const uint16 bom = stream.readUint16BE();
	if ((bom != 0xFFFE) && (bom != 0xFEFF))
		throw Common::Exception("Invalid BOM: 0x%04X", (uint) bom);

	return bom == 0xFEFF;
}
Ejemplo n.º 17
0
bool TotFunctions::loadIDE(Tot &tot) {
	// Mapping file of function names -> function numbers/offsets
	Common::String ideFile = Util::setExtension(tot.file, ".IDE");
	Common::SeekableReadStream *ide = _vm->_dataIO->getFile(ideFile);
	if (!ide)
		// No mapping file => No named functions
		return true;

	char buffer[17];

	uint32 count = ide->readUint16LE();
	for (uint32 i = 0; i < count; i++) {
		Function function;

		function.type = ide->readByte();

		ide->read(buffer, 17);
		buffer[16] = '\0';

		function.name = buffer;

		ide->skip(2); // Unknown;
		function.offset = ide->readUint16LE();
		ide->skip(2); // Unknown;

		if ((function.type != 0x47) && (function.type != 0x67))
			continue;

		tot.script->seek(function.offset);

		if (tot.script->readByte() != 1) {
			warning("TotFunctions::loadIDE(): IDE corrupt");
			return false;
		}

		debugC(5, kDebugGameFlow, "Function 0x%02X: \"%s\"", function.type,
				function.name.c_str());
		tot.functions.push_back(function);
	}

	tot.script->seek(0);
	return true;
}
Ejemplo n.º 18
0
void Frame::load(byte *dataStart, Common::SeekableReadStream &stream) {
	_flags = stream.readUint16LE();
	stream.skip(2); // Skip padding
	uint32 pointsConfigOffs = stream.readUint32LE();
	_surfInfo.load(stream);
	uint32 compressedPixelsOffs = stream.readUint32LE();
	_compressedPixels = dataStart + compressedPixelsOffs;
	_pointsConfig = dataStart + pointsConfigOffs;
	debug(5, "Frame::load() compressedPixelsOffs: %08X",
		compressedPixelsOffs);
}
Ejemplo n.º 19
0
void PScr::loadSurface(Common::SeekableReadStream &stream) {
	stream.skip(4);
	int width = stream.readUint16LE();
	int height = stream.readUint16LE();
	_surface = new Graphics::Surface();
	_surface->create(width, height, Graphics::PixelFormat::createFormatCLUT8());

	for (int h = 0; h < _surface->h; h++) {
		stream.read(_surface->getBasePtr(0, h), _surface->w);
	}
}
Ejemplo n.º 20
0
void DirectorySubEntry::readFromStream(Common::SeekableReadStream &inStream) {
    _offset = inStream.readUint32LE();
    _size = inStream.readUint32LE();
    _metadataSize = inStream.readUint16LE();
    _face = inStream.readByte();
    _type = static_cast<ResourceType>(inStream.readByte());

    if (_metadataSize == 2 && (_type == kSpotItem || _type == kLocalizedSpotItem)) {
        _spotItemData.u = inStream.readUint32LE();
        _spotItemData.v = inStream.readUint32LE();
    } else if (_metadataSize == 10 && (_type == kMovie || _type == kMultitrackMovie)) {
        _videoData.v1.setValue(0, inStream.readSint32LE() * 0.000001f);
        _videoData.v1.setValue(1, inStream.readSint32LE() * 0.000001f);
        _videoData.v1.setValue(2, inStream.readSint32LE() * 0.000001f);

        _videoData.v2.setValue(0, inStream.readSint32LE() * 0.000001f);
        _videoData.v2.setValue(1, inStream.readSint32LE() * 0.000001f);
        _videoData.v2.setValue(2, inStream.readSint32LE() * 0.000001f);

        _videoData.u = inStream.readSint32LE();
        _videoData.v = inStream.readSint32LE();
        _videoData.width = inStream.readSint32LE();
        _videoData.height = inStream.readSint32LE();
    } else if (_type == kNumMetadata || _type == kTextMetadata) {
        if (_metadataSize > 20) {
            warning("Too much metadata, skipping");
            inStream.skip(_metadataSize * sizeof(uint32));
            return;
        }

        _miscData[0] = _offset;
        _miscData[1] = _size;

        for (uint i = 0; i < _metadataSize; i++)
            _miscData[i + 2] = inStream.readUint32LE();
    } else if (_metadataSize != 0) {
        warning("Metadata not read for type %d, size %d", _type, _metadataSize);
        inStream.skip(_metadataSize * sizeof(uint32));
    }
}
Ejemplo n.º 21
0
void KEYFile::load(Common::SeekableReadStream &key) {
	readHeader(key);

	if (_id != kKEYID)
		throw Common::Exception("Not a KEY file (%s)", Common::debugTag(_id).c_str());

	if ((_version != kVersion1) && (_version != kVersion11))
		throw Common::Exception("Unsupported KEY file version %s", Common::debugTag(_version).c_str());

	uint32 bifCount = key.readUint32LE();
	uint32 resCount = key.readUint32LE();

	_bifs.reserve(bifCount);
	_resources.reserve(resCount);

	// Version 1.1 has some NULL bytes here
	if (_version == kVersion11)
		key.skip(4);

	uint32 offFileTable     = key.readUint32LE();
	uint32 offResTable      = key.readUint32LE();

	key.skip( 8); // Build year and day
	key.skip(32); // Reserved

	try {

		_bifs.resize(bifCount);
		readBIFList(key, offFileTable);

		_resources.resize(resCount);
		readResList(key, offResTable);

	} catch (Common::Exception &e) {
		e.add("Failed reading KEY file");
		throw;
	}

}
Ejemplo n.º 22
0
bool Cursor::loadStream(Common::SeekableReadStream &stream) {
	stream.skip(4);
	uint16 width = stream.readUint16LE();
	uint16 height = stream.readUint16LE();

	_surface = new Graphics::Surface();
	_surface->create(width, height, Graphics::PixelFormat::createFormatCLUT8());

	for (int h = 0; h < height; h++) {
		stream.read(_surface->getBasePtr(0, h), width);
	}
	return true;
}
Ejemplo n.º 23
0
/**
 * Read _invent from Hugo.dat
 */
void InventoryHandler::loadInvent(Common::SeekableReadStream &in) {
	for (int varnt = 0; varnt < _vm->_numVariant; varnt++) {
		int16 numElem = in.readUint16BE();
		if (varnt == _vm->_gameVariant) {
			_maxInvent = numElem;
			_invent = (int16 *)malloc(sizeof(int16) * numElem);
			for (int i = 0; i < numElem; i++)
				_invent[i] = in.readSint16BE();
		} else {
			in.skip(numElem * sizeof(int16));
		}
	}
}
Ejemplo n.º 24
0
void ERFFile::readERFHeader(Common::SeekableReadStream &erf, ERFHeader &header) {
	uint32 resCount = 0;

	if        (_version == kVersion1) {

		header.langCount = erf.readUint32LE(); // Number of languages for the description
		erf.skip(4);                           // Number of bytes in the description
		resCount         = erf.readUint32LE(); // Number of resources in the ERF

		header.offDescription = erf.readUint32LE();
		header.offKeyList     = erf.readUint32LE();
		header.offResList     = erf.readUint32LE();

		erf.skip(4 + 4); // Build year and day

		header.descriptionID = erf.readUint32LE();

		erf.skip(116); // Reserved

	} else if (_version == kVersion2) {

		header.langCount = 0;                  // No description in ERF V2.0
		resCount         = erf.readUint32LE(); // Number of resources in the ERF

		header.descriptionID  = 0;    // No description in ERF V2.0
		header.offDescription = 0;    // No description in ERF V2.0
		header.offKeyList     = 0;    // No separate key list in ERF V2.0
		header.offResList     = 0x20; // Resource list always starts at 0x20 in ERF V2.0

		erf.skip(4 + 4); // Build year and day
		erf.skip(4);     // Unknown, always 0xFFFFFFFF?
	}

	if (!_noResources) {
		_resources.resize(resCount);
		_iResources.resize(resCount);
	}
}
Ejemplo n.º 25
0
bool ADLPlayer::readHeader(Common::SeekableReadStream &adl, int &timbreCount) {
	// Sanity check
	if (adl.size() < 60) {
		warning("ADLPlayer::readHeader(): File too small (%d)", adl.size());
		return false;
	}

	_soundMode  = adl.readByte();
	timbreCount = adl.readByte() + 1;

	adl.skip(1);

	return true;
}
Ejemplo n.º 26
0
void GameModule::loadInventoryItemInfos(Common::SeekableReadStream &s) {
	debug(0, "GameModule::loadInventoryItemInfos()");

	s.seek(0x190);
	uint32 offs = s.readUint32LE();
	s.seek(offs);
	for (int i = 0; i < kInventoryItemCount; ++i) {
		_inventoryItemInfos[i].xOffs = s.readUint16LE();
		_inventoryItemInfos[i].yOffs = s.readUint16LE();
		_inventoryItemInfos[i].width = s.readUint16LE();
		_inventoryItemInfos[i].height = s.readUint16LE();
		s.skip(8); // Unused
	}
}
Ejemplo n.º 27
0
void RIMFile::readResList(Common::SeekableReadStream &rim, uint32 offset) {
	rim.seek(offset);

	uint32 index = 0;
	ResourceList::iterator   res = _resources.begin();
	IResourceList::iterator iRes = _iResources.begin();
	for (; (res != _resources.end()) && (iRes != _iResources.end()); ++index, ++res, ++iRes) {
		res->name    = Common::readStringFixed(rim, Common::kEncodingASCII, 16);
		res->type    = (FileType) rim.readUint16LE();
		res->index   = index;
		rim.skip(4 + 2); // Resource ID + Reserved
		iRes->offset = rim.readUint32LE();
		iRes->size   = rim.readUint32LE();
	}
}
Ejemplo n.º 28
0
void Sprite::loadPalette(Common::SeekableReadStream &stream, uint32 count) {
	if (count == 0)
		return;

	byte *palette = new byte[count * 3];
	for (uint32 i = 0; i < count ; i++) {
		palette[i * 3 + 2] = stream.readByte();
		palette[i * 3 + 1] = stream.readByte();
		palette[i * 3 + 0] = stream.readByte();

		stream.skip(1);
	}
	_palette.copyFrom(palette, count);
	delete[] palette;
}
Ejemplo n.º 29
0
void TwoDAFile::readRows2b(Common::SeekableReadStream &twoda) {
	/* And now read the cells. In binary 2DA files, each cell only
	 * stores a single 16-bit number, the offset into the data segment
	 * where the data for this cell can be found. Moreover, a single
	 * data offset can be used by several cells, deduplicating the
	 * cell data.
	 */

	size_t columnCount = _headers.size();
	size_t rowCount    = _rows.size();
	size_t cellCount   = columnCount * rowCount;

	uint32 *offsets = new uint32[cellCount];

	Common::StreamTokenizer tokenize(Common::StreamTokenizer::kRuleHeed);

	tokenize.addSeparator('\0');

	for (size_t i = 0; i < cellCount; i++)
		offsets[i] = twoda.readUint16LE();

	twoda.skip(2); // Size of the data segment in bytes

	size_t dataOffset = twoda.pos();

	for (size_t i = 0; i < rowCount; i++) {
		_rows[i] = new TwoDARow(*this);

		_rows[i]->_data.resize(columnCount);

		for (size_t j = 0; j < columnCount; j++) {
			size_t offset = dataOffset + offsets[i * columnCount + j];

			try {
				twoda.seek(offset);
			} catch (...) {
				delete[] offsets;
				throw;
			}

			_rows[i]->_data[j] = tokenize.getToken(twoda);
			if (_rows[i]->_data[j].empty())
				_rows[i]->_data[j] = "****";
		}
	}

	delete[] offsets;
}
Ejemplo n.º 30
0
/**
 * Read _introX and _introY from hugo.dat
 */
void IntroHandler::loadIntroData(Common::SeekableReadStream &in) {
	for (int varnt = 0; varnt < _vm->_numVariant; varnt++) {
		int numRows = in.readUint16BE();
		if (varnt == _vm->_gameVariant) {
			_introXSize = numRows;
			_introX = (byte *)malloc(sizeof(byte) * _introXSize);
			_introY = (byte *)malloc(sizeof(byte) * _introXSize);
			for (int i = 0; i < _introXSize; i++) {
				_introX[i] = in.readByte();
				_introY[i] = in.readByte();
			}
		} else {
			in.skip(numRows * 2);
		}
	}
}