Exemplo n.º 1
0
void TTtagMappings::load(const char *name) {
	Common::SeekableReadStream *r = g_vm->_filesManager->getResource(name);

	while (r->pos() < r->size()) {
		uint src = r->readUint32LE();
		uint dest = r->readUint32LE();

		push_back(TTtagMapping(src, dest));
	}

	delete r;
}
Exemplo n.º 2
0
uint32 GFF4Struct::getListCount(Common::SeekableReadStream &data, const Field &field) const {
	if (!field.isList)
		return 1;

	const uint32 listOffset = data.readUint32LE();
	if (listOffset == 0xFFFFFFFF)
		return 0;

	data.seek(_parent->getDataOffset() + listOffset);

	return data.readUint32LE();
}
Exemplo n.º 3
0
void GameModule::loadSceneExits(Common::SeekableReadStream &s) {
	debug(0, "GameModule::loadSceneExits()");

	s.seek(0x158);
	_sceneExitsCount = s.readUint32LE();
	uint32 offs = s.readUint32LE();
	_sceneExits = new SceneExit[_sceneExitsCount];
	s.seek(offs);
	for (int i = 0; i < _sceneExitsCount; ++i) {
		_sceneExits[i].rect = readRect(s);
		_sceneExits[i].newModuleNum = s.readUint32LE();
	}
}
Exemplo n.º 4
0
void GameModule::loadBgObjects(Common::SeekableReadStream &s) {
	debug(0, "GameModule::loadBgObjects()");

	s.seek(0x160);
	_bgObjectsCount = s.readUint32LE();
	uint32 offs = s.readUint32LE();
	_bgObjects = new BgObject[_bgObjectsCount];
	s.seek(offs);
	for (int i = 0; i < _bgObjectsCount; ++i) {
		s.read(_bgObjects[i].name, 20);
		_bgObjects[i].rect = readRect(s);
	}
}
Exemplo n.º 5
0
void GameModule::loadSceneSounds(Common::SeekableReadStream &s) {
	debug(0, "GameModule::loadSceneSounds()");

	s.seek(0x1A0);
	_sceneSoundsCount = s.readUint32LE();
	uint32 offs = s.readUint32LE();
	_sceneSounds = new SceneSound[_sceneSoundsCount];
	s.seek(offs);
	for (int i = 0; i < _sceneSoundsCount; ++i) {
		_sceneSounds[i].conditions = readConditions(s);
		_sceneSounds[i].soundNum = s.readUint32LE();
	}
}
Exemplo n.º 6
0
void TTmapEntryArray::load(const char *name) {
	Common::SeekableReadStream *r = g_vm->_filesManager->getResource(name);

	while (r->pos() < r->size()) {
		TTmapEntry us;
		us._src = r->readUint32LE();
		us._dest = r->readUint32LE();

		push_back(us);
	}

	delete r;
}
Exemplo n.º 7
0
void CBaseStarEntry::load(Common::SeekableReadStream &s) {
	_field0 = s.readByte();
	_field1 = s.readByte();
	_field2 = s.readByte();
	_field3 = s.readByte();
	*((uint32 *)&_value) = s.readUint32LE();		// FIXME
	_val._v1 = s.readUint32LE();
	_val._v2 = s.readUint32LE();
	_val._v3 = s.readUint32LE();

	for (int idx = 0; idx < 5; ++idx)
		_data[idx] = s.readUint32LE();
}
Exemplo n.º 8
0
void TTupdateStateArray::load(const char *name) {
	Common::SeekableReadStream *r = g_vm->_filesManager->getResource(name);

	while (r->pos() < r->size()) {
		TTupdateState us;
		us._newId = r->readUint32LE();
		us._newValue = r->readUint32LE();
		us._dialBits = r->readUint32LE();

		push_back(us);
	}

	delete r;
}
Exemplo n.º 9
0
void Model::readArrayDef(Common::SeekableReadStream &stream,
                         uint32 &offset, uint32 &count) {

	offset = stream.readUint32LE();

	uint32 usedCount      = stream.readUint32LE();
	uint32 allocatedCount = stream.readUint32LE();

	if (usedCount != allocatedCount)
		warning("Model::readArrayDef(): usedCount != allocatedCount (%d, %d)",
		        usedCount, allocatedCount);

	count = usedCount;
}
Exemplo n.º 10
0
void CBaseStar::loadData(Common::SeekableReadStream &s) {
	uint headerId = s.readUint32LE();
	uint count = s.readUint32LE();
	if (headerId != 100 || count == 0)
		error("Invalid star data");

	// Initialize the data array
	clear();
	_data.resize(count);

	// Iterate through reading the data for each entry
	for (uint idx = 0; idx < count; ++idx)
		_data[idx].load(s);
}
Exemplo n.º 11
0
void XEOSITEX::readMipMaps(Common::SeekableReadStream &xeositex) {
	for (uint32 i = 0; i < _mipMaps.size(); i++) {
		_mipMaps[i] = new MipMap;

		_mipMaps[i]->width  = xeositex.readUint32LE();
		_mipMaps[i]->height = xeositex.readUint32LE();
		_mipMaps[i]->size   = xeositex.readUint32LE();

		_mipMaps[i]->data = new byte[_mipMaps[i]->size];

		if (xeositex.read(_mipMaps[i]->data, _mipMaps[i]->size) != _mipMaps[i]->size)
			throw Common::Exception(Common::kReadError);
	}
}
Exemplo n.º 12
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();
	}
}
Exemplo n.º 13
0
bool StaticResource::loadCharData(Common::SeekableReadStream &stream, void *&ptr, int &size) {
	size = stream.size() / 130;
	LoLCharacter *charData = new LoLCharacter[size];

	for (int i = 0; i < size; i++) {
		LoLCharacter *t = &charData[i];

		t->flags = stream.readUint16LE();
		stream.read(t->name, 11);
		t->raceClassSex = stream.readByte();
		t->id = stream.readSint16LE();
		t->curFaceFrame = stream.readByte();
		t->tempFaceFrame = stream.readByte();
		t->screamSfx = stream.readByte();
		stream.readUint32LE();
		for (int ii = 0; ii < 8; ii++)
			t->itemsMight[ii] = stream.readUint16LE();
		for (int ii = 0; ii < 8; ii++)
			t->protectionAgainstItems[ii] = stream.readUint16LE();
		t->itemProtection = stream.readUint16LE();
		t->hitPointsCur = stream.readSint16LE();
		t->hitPointsMax = stream.readUint16LE();
		t->magicPointsCur = stream.readSint16LE();
		t->magicPointsMax = stream.readUint16LE();
		t->field_41 = stream.readByte();
		t->damageSuffered = stream.readUint16LE();
		t->weaponHit = stream.readUint16LE();
		t->totalMightModifier = stream.readUint16LE();
		t->totalProtectionModifier = stream.readUint16LE();
		t->might = stream.readUint16LE();
		t->protection = stream.readUint16LE();
		t->nextAnimUpdateCountdown = stream.readSint16LE();
		for (int ii = 0; ii < 11; ii++)
			t->items[ii] = stream.readUint16LE();
		for (int ii = 0; ii < 3; ii++)
			t->skillLevels[ii] = stream.readByte();
		for (int ii = 0; ii < 3; ii++)
			t->skillModifiers[ii] = stream.readByte();
		for (int ii = 0; ii < 3; ii++)
			t->experiencePts[ii] = stream.readUint32LE();
		for (int ii = 0; ii < 5; ii++)
			t->characterUpdateEvents[ii] = stream.readByte();
		for (int ii = 0; ii < 5; ii++)
			t->characterUpdateDelay[ii] = stream.readByte();
	};

	ptr = charData;
	return true;
}
Exemplo n.º 14
0
void KEYFile::readResList(Common::SeekableReadStream &key, uint32 offset) {
	key.seek(offset);

	for (ResourceList::iterator res = _resources.begin(); res != _resources.end(); ++res) {
		res->name = Common::readStringFixed(key, Common::kEncodingASCII, 16);
		res->type = (FileType) key.readUint16LE();

		uint32 id = key.readUint32LE();

		// The new flags field holds the bifIndex now. The rest contains fixed
		// resource info.
		if (_version == kVersion11) {
			uint32 flags = key.readUint32LE();
			res->bifIndex = (flags & 0xFFF00000) >> 20;
		} else
Exemplo n.º 15
0
void TTscriptMappings::load(const char *name, int valuesPerMapping) {
	Common::SeekableReadStream *r = g_vm->_filesManager->getResource(name);
	_valuesPerMapping = valuesPerMapping;

	while (r->pos() < r->size()) {
		resize(size() + 1);
		TTscriptMapping &m = (*this)[size() - 1];

		m._id = r->readUint32LE();
		for (int idx = 0; idx < valuesPerMapping; ++idx)
			m._values[idx] = r->readUint32LE();
	}

	delete r;
}
Exemplo n.º 16
0
void TTcommonPhraseArray::load(const char *name) {
	Common::SeekableReadStream *r = g_vm->_filesManager->getResource(name);

	while (r->pos() < r->size()) {
		TTcommonPhrase cp;
		cp._str = readStringFromStream(r);
		cp._dialogueId = r->readUint32LE();
		cp._roomNum = r->readUint32LE();
		cp._val1 = r->readUint32LE();

		push_back(cp);
	}

	delete r;
}
Exemplo n.º 17
0
void GameModule::loadSceneObjectDefs(Common::SeekableReadStream &s) {
	debug(0, "GameModule::loadSceneObjectDefs()");

	s.seek(0x170);
	_sceneObjectDefsCount = s.readUint32LE();
	uint32 offs = s.readUint32LE();
	_sceneObjectDefs = new SceneObjectDef[_sceneObjectDefsCount];
	s.seek(offs);
	for (int i = 0; i < _sceneObjectDefsCount; ++i) {
		s.read(_sceneObjectDefs[i].name, 20);
		_sceneObjectDefs[i].walkSpeed = s.readUint32LE();
		for (int j = 0; j < 16; ++j)
			_sceneObjectDefs[i].animIndices[j] = s.readUint32LE();
	}
}
Exemplo n.º 18
0
bool Mob::loadFromStream(Common::SeekableReadStream &stream) {
	int32 pos = stream.pos();

	uint16 visible = stream.readUint16LE();

	if (visible == 0xFFFF)
		return false;

	_visible = visible;
	_type = stream.readUint16LE();
	_rect.left = stream.readUint16LE();
	_rect.top = stream.readUint16LE();
	_rect.right = stream.readUint16LE();
	_rect.bottom = stream.readUint16LE();

	_mask = stream.readUint16LE();

	_examPosition.x = stream.readUint16LE();
	_examPosition.y = stream.readUint16LE();
	_examDirection = (Direction)stream.readUint16LE();

	_usePosition.x = stream.readByte();
	_usePosition.y = stream.readByte();
	_useDirection = (Direction)stream.readUint16LE();

	uint32 nameOffset = stream.readUint32LE();
	uint32 examTextOffset = stream.readUint32LE();

	byte c;
	stream.seek(nameOffset);
	_name.clear();
	while ((c = stream.readByte()))
		_name += c;

	stream.seek(examTextOffset);
	_examText.clear();
	c = stream.readByte();
	if (c) {
		_examText += c;
		do {
			c = stream.readByte();
			_examText += c;
		} while (c != 255);
	}
	stream.seek(pos + 32);

	return true;
}
Exemplo n.º 19
0
void LocString::readString(Language language, Common::SeekableReadStream &stream) {
	uint32 length = stream.readUint32LE();

	// TODO: Different encodings for different languages, probably
	_strings[mapLanguageToStorage(language)].readFixedLatin9(stream, length, true);
	_languages[mapLanguageToStorage(language)] = language;
}
Exemplo n.º 20
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;
}
Exemplo n.º 21
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;
}
Exemplo n.º 22
0
int64 GFF4Struct::getSint(Common::SeekableReadStream &data, IFieldType type) const {
	switch (type) {
		case kIFieldTypeUint8:
			return (int64) ((uint64) data.readByte());

		case kIFieldTypeSint8:
			return (int64) data.readSByte();

		case kIFieldTypeUint16:
			return (int64) ((uint64) data.readUint16LE());

		case kIFieldTypeSint16:
			return (int64) data.readSint16LE();

		case kIFieldTypeUint32:
			return (int64) ((uint64) data.readUint32LE());

		case kIFieldTypeSint32:
			return (int64) data.readSint32LE();

		case kIFieldTypeUint64:
			return (int64) ((uint64) data.readUint64LE());

		case kIFieldTypeSint64:
			return (int64) data.readSint64LE();

		default:
			break;
	}

	throw Common::Exception("GFF4: Field is not an int type");
}
Exemplo n.º 23
0
SSFFile::Version SSFFile::readSSFHeader(Common::SeekableReadStream &ssf,
                                        size_t &entryCount, size_t &offEntryTable) {
	readHeader(ssf);

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

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

	entryCount    = ssf.readUint32LE();
	offEntryTable = ssf.readUint32LE();

	// Plain old version V1.0 used in NWN (and NWN2)
	if (_version == kVersion10)
		return kVersion10_NWN;

	// NWN2's V1.1
	if ((offEntryTable < ssf.size()) && ((ssf.size() - offEntryTable) >= ((4 + 32 + 4) * entryCount)))
		return kVersion11_NWN2;

	offEntryTable = entryCount;
	entryCount    = (ssf.size() - offEntryTable) / 4;

	// Sanity check
	if ((offEntryTable > ssf.size()) || (((ssf.size() - offEntryTable) % 4) != 0))
		throw Common::Exception("Invalid SSF header (%u, %u)", (uint32) ssf.size(), (uint32) offEntryTable);

	// KotOR's V1.1
	return kVersion11_KotOR;
}
Exemplo n.º 24
0
void SurfInfo::load(Common::SeekableReadStream &stream) {
	_pixelSize = stream.readUint32LE();
	_dimensions.load(stream);

	debug(5, "SurfInfo::load() _pixelSize: %d",
		_pixelSize);
}
Exemplo n.º 25
0
bool TGADecoder::readColorMap(Common::SeekableReadStream &tga, byte imageType, byte pixelDepth) {
	_colorMap = new byte[3 * _colorMapLength];
	for (int i = 0; i < _colorMapLength * 3; i += 3) {
		byte r, g, b;
		if (_colorMapEntryLength == 32) {
			byte a;
			Graphics::PixelFormat format(4, 8, 8, 8, 0, 16, 8, 0, 24);
			uint32 color = tga.readUint32LE();
			format.colorToARGB(color, a, r, g, b);
		} else if (_colorMapEntryLength == 24) {
			r = tga.readByte();
			g = tga.readByte();
			b = tga.readByte();
		} else if (_colorMapEntryLength == 16) {
			byte a;
			Graphics::PixelFormat format(2, 5, 5, 5, 0, 10, 5, 0, 15);
			uint16 color = tga.readUint16LE();
			format.colorToARGB(color, a, r, g, b);
		} else {
			warning("Unsupported image type: %d", imageType);
			r = g = b = 0;
		}
#ifdef SCUMM_LITTLE_ENDIAN
		_colorMap[i] = r;
		_colorMap[i + 1] = g;
		_colorMap[i + 2] = b;
#else
		_colorMap[i] = b;
		_colorMap[i + 1] = g;
		_colorMap[i + 2] = r;
#endif
	}
	return true;
}
Exemplo n.º 26
0
void DirectorEngine::loadEXE() {
    Common::SeekableReadStream *exeStream = SearchMan.createReadStreamForMember(getEXEName());
    if (!exeStream)
        error("Failed to open EXE '%s'", getEXEName().c_str());

    _lingo->processEvent(kEventStart, 0);

    exeStream->seek(-4, SEEK_END);
    exeStream->seek(exeStream->readUint32LE());

    switch (getVersion()) {
    case 3:
        loadEXEv3(exeStream);
        break;
    case 4:
        loadEXEv4(exeStream);
        break;
    case 5:
        loadEXEv5(exeStream);
        break;
    case 7:
        loadEXEv7(exeStream);
        break;
    default:
        error("Unhandled Windows EXE version %d", getVersion());
    }
}
Exemplo n.º 27
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;
	}

}
Exemplo n.º 28
0
void GameModule::loadSceneObjectInits(Common::SeekableReadStream &s) {
	debug(0, "GameModule::loadSceneObjectInits()");

	s.seek(0x178);
	_sceneObjectInitsCount = s.readUint32LE();
	uint32 offs = s.readUint32LE();
	_sceneObjectInits = new SceneObjectInit[_sceneObjectInitsCount];
	s.seek(offs);
	for (int i = 0; i < _sceneObjectInitsCount; ++i) {
		_sceneObjectInits[i].conditions = readConditions(s);
		_sceneObjectInits[i].sceneObjectIndex = s.readUint32LE();
		_sceneObjectInits[i].animIndex = s.readUint32LE();
		_sceneObjectInits[i].x = s.readUint16LE();
		_sceneObjectInits[i].y = s.readUint16LE();
	}
}
Exemplo n.º 29
0
bool ComposerEngine::initSprite(Sprite &sprite) {
	Common::SeekableReadStream *stream = getStreamForSprite(sprite._id);
	if (!stream)
		return false;

	uint16 type = stream->readUint16LE();
	int16 height = stream->readSint16LE();
	int16 width = stream->readSint16LE();
	uint32 size = stream->readUint32LE();
	debug(1, "loading BMAP: type %d, width %d, height %d, size %d", type, width, height, size);

	if (width > 0 && height > 0) {
		sprite._surface.create(width, height, Graphics::PixelFormat::createFormatCLUT8());
		decompressBitmap(type, stream, (byte *)sprite._surface.getPixels(), size, width, height);
	} else {
		// there are some sprites (e.g. a -998x-998 one in Gregory's title screen)
		// which have an invalid size, but the original engine doesn't notice for
		// RLE sprites since the width/height is ignored until the actual draw
		if (type != kBitmapRLESLWM)
			error("sprite (type %d) had invalid size %dx%d", type, width, height);
		delete stream;
		return false;
	}
	delete stream;

	return true;
}
Exemplo n.º 30
0
void Graphics::loadMRG(Common::String filename, MRGFile *mrg) {
	Common::SeekableReadStream *mrgStream = _vm->data.openFile(filename);
	uint16 num_entries = mrgStream->readUint16LE();

	Common::Array<uint32> offsets;
	for (unsigned int i = 0; i < num_entries; i++) {
		offsets.push_back(mrgStream->readUint32LE());
	}

	for (unsigned int i = 0; i < num_entries; i++) {
		bool r = mrgStream->seek(offsets[i], SEEK_SET);
		assert(r);

		uint16 width = mrgStream->readUint16LE();
		uint16 height = mrgStream->readUint16LE();
		byte *pixels = new byte[width * height];
		mrgStream->read(pixels, width * height);

		mrg->heights.push_back(height);
		mrg->widths.push_back(width);
		mrg->data.push_back(pixels);
	}

	delete mrgStream;
}