Exemple #1
0
void AGOSEngine_PN::loadGamePcFile() {
	if (getFileName(GAME_BASEFILE) != NULL) {
		Common::File in;
		// Read dataBase
		if (!in.open(getFileName(GAME_BASEFILE))) {
			error("loadGamePcFile: Can't load database file '%s'", getFileName(GAME_BASEFILE));
		}

		_dataBaseSize = in.size();
		_dataBase = (byte *)malloc(_dataBaseSize);
		if (_dataBase == NULL)
			error("loadGamePcFile: Out of memory for dataBase");
		in.read(_dataBase, _dataBaseSize);

		if (_dataBase[31] != 0)
			error("Later version of system requested");
	}

	if (getFileName(GAME_TEXTFILE) != NULL) {
		Common::File in;
		// Read textBase
		if (!in.open(getFileName(GAME_TEXTFILE))) {
			error("loadGamePcFile: Can't load textbase file '%s'", getFileName(GAME_TEXTFILE));
		}

		_textBaseSize = in.size();
		_textBase = (byte *)malloc(_textBaseSize);
		if (_textBase == NULL)
			error("loadGamePcFile: Out of memory for textBase");
		in.read(_textBase, _textBaseSize);

		if (_textBase[getlong(30L)] != 128)
			error("Unknown compression format");
	}
}
Exemple #2
0
bool TeenAgentEngine::showCDLogo() {
	Common::File cdlogo;
	if (!cdlogo.exists("cdlogo.res") || !cdlogo.open("cdlogo.res"))
		return true;

	byte bg[0xfa00];
	byte palette[3*256];

	cdlogo.read(bg, sizeof(bg));
	cdlogo.read(palette, sizeof(palette));
	for (uint c = 0; c < 3*256; ++c)
		palette[c] *= 4;
	_system->getPaletteManager()->setPalette(palette, 0, 0x100);
	_system->copyRectToScreen(bg, 320, 0, 0, 320, 200);
	_system->updateScreen();

	for(uint i = 0; i < 20; ++i) {
		int r = skipEvents();
		if (r != 0)
			return r > 0? true: false;
		_system->delayMillis(100);
	}
	cdlogo.close();

	return true;
}
Exemple #3
0
/**
 * This function does noting but load a raw resource into memory,
 * if further decoding is required, it must be done by another
 * routine. NULL is returned if unsucsessfull.
 */
uint8 *AgiLoader_v2::loadVolRes(struct AgiDir *agid) {
	uint8 *data = NULL;
	char x[MAXPATHLEN], *path;
	Common::File fp;
	unsigned int sig;

	sprintf(x, "vol.%i", agid->volume);
	path = x;
	debugC(3, kDebugLevelResources, "Vol res: path = %s", path);

	if (agid->offset != _EMPTY && fp.open(path)) {
		debugC(3, kDebugLevelResources, "loading resource at offset %d", agid->offset);
		fp.seek(agid->offset, SEEK_SET);
		fp.read(&x, 5);
		if ((sig = READ_BE_UINT16((uint8 *) x)) == 0x1234) {
			agid->len = READ_LE_UINT16((uint8 *) x + 3);
			data = (uint8 *) calloc(1, agid->len + 32);
			if (data != NULL) {
				fp.read(data, agid->len);
			} else {
				exit(1);
			}
		} else {
			warning("AgiLoader_v2::loadVolRes: bad signature %04x", sig);
			return 0;
		}
		fp.close();
	} else {
		// we have a bad volume resource
		// set that resource to NA
		agid->offset = _EMPTY;
	}

	return data;
}
Exemple #4
0
 // FIXME/TODO: 아래는 코드 중복 모음
 void loadEmergencyFont()
 {
     Common::File fp;
     int numChar = 0;
     
     numChar = 2350;
     if (fp.open("korean.fnt")) {
         fp.seek(2, SEEK_CUR);
         _korFontWidth = fp.readByte();
         _korFontHeight = fp.readByte();
         _korFontPtr = new byte[((_korFontWidth + 7) / 8) * _korFontHeight * numChar];
         
         fp.read(_korFontPtr, ((_korFontWidth + 7) / 8) * _korFontHeight * numChar);
         fp.close();
         warning("V1 한글 폰트가 로드되었습니다.\n");
     } else {
         warning("V1 한글 폰트를 로드할 수 없습니다!\n");
     }
     
     numChar = 256;
     if (fp.open("english.fnt")) {
         fp.seek(2, SEEK_CUR);
         _engFontWidth = fp.readByte();
         _engFontHeight = fp.readByte();
         _engFontPtr = new byte[((_engFontWidth + 7) / 8) * _engFontHeight * numChar];
         
         fp.read(_engFontPtr, ((_engFontWidth + 7) / 8) * _engFontHeight * numChar);
         fp.close();
         warning("V1 영문 폰트가 로드되었습니다.\n");
     } else {
         warning("V1 영문 폰트를 로드할 수 없습니다!\n");
     }
 }
Exemple #5
0
void AGOSEngine::decompressData(const char *srcName, byte *dst, uint32 offset, uint32 srcSize, uint32 dstSize) {
#ifdef USE_ZLIB
		Common::File in;
		in.open(srcName);
		if (in.isOpen() == false)
			error("decompressData: Can't load %s", srcName);

		in.seek(offset, SEEK_SET);
		if (srcSize != dstSize) {
			byte *srcBuffer = (byte *)malloc(srcSize);

			if (in.read(srcBuffer, srcSize) != srcSize)
				error("decompressData: Read failed");

			unsigned long decompressedSize = dstSize;
			if (!Common::uncompress(dst, &decompressedSize, srcBuffer, srcSize))
				error("decompressData: Zlib uncompress error");
			free(srcBuffer);
		} else {
			if (in.read(dst, dstSize) != dstSize)
				error("decompressData: Read failed");
		}
		in.close();
#else
	error("Zlib support is required for Amiga and Macintosh versions");
#endif
}
Exemple #6
0
/**
 * Loads the contents of the mort.dat data file
 */
Common::ErrorCode MortevielleEngine::loadMortDat() {
	Common::File f;

	// Open the mort.dat file
	if (!f.open(MORT_DAT)) {
		Common::String msg = Common::String::format(_("Unable to locate the '%s' engine data file."), MORT_DAT);
		GUIErrorMessage(msg);
		return Common::kReadingFailed;
	}

	// Validate the data file header
	char fileId[4];
	f.read(fileId, 4);
	if (strncmp(fileId, "MORT", 4) != 0) {
		Common::String msg = Common::String::format(_("The '%s' engine data file is corrupt."), MORT_DAT);
		GUIErrorMessage(msg);
		return Common::kReadingFailed;
	}

	// Check the version
	int majVer = f.readByte();
	int minVer = f.readByte();

	if (majVer < MORT_DAT_REQUIRED_VERSION) {
		Common::String msg = Common::String::format(
			_("Incorrect version of the '%s' engine data file found. Expected %d.%d but got %d.%d."),
			MORT_DAT, MORT_DAT_REQUIRED_VERSION, 0, majVer, minVer);
		GUIErrorMessage(msg);
		return Common::kReadingFailed;
	}

	// Loop to load resources from the data file
	while (f.pos() < f.size()) {
		// Get the Id and size of the next resource
		char dataType[4];
		int dataSize;
		f.read(dataType, 4);
		dataSize = f.readUint16LE();

		if (!strncmp(dataType, "FONT", 4)) {
			// Font resource
			_screenSurface->readFontData(f, dataSize);
		} else if (!strncmp(dataType, "SSTR", 4)) {
			readStaticStrings(f, dataSize, kStaticStrings);
		} else if ((!strncmp(dataType, "GSTR", 4)) && (!_txxFileFl)) {
			readStaticStrings(f, dataSize, kGameStrings);
		} else if (!strncmp(dataType, "VERB", 4)) {
			_menu->readVerbNums(f, dataSize);
		} else {
			// Unknown section
			f.skip(dataSize);
		}
	}

	// Close the file
	f.close();

	assert(_engineStrings.size() > 0);
	return Common::kNoError;
}
Exemple #7
0
bool TeenAgentEngine::showCDLogo() {
	Common::File cdlogo;
	if (!cdlogo.exists("cdlogo.res") || !cdlogo.open("cdlogo.res"))
		return true;

	byte bg[0xfa00];
	byte palette[0x400];

	cdlogo.read(bg, sizeof(bg));
	memset(palette, 0, sizeof(palette));

	for(uint c = 0; c < 0x100; ++c) {
		uint idx = c * 4;
		cdlogo.read(palette + idx, 3);
		palette[idx] *= 4;
		palette[idx + 1] *= 4;
		palette[idx + 2] *= 4;
	}
	_system->setPalette(palette, 0, 0x100);
	_system->copyRectToScreen(bg, 320, 0, 0, 320, 200);
	_system->updateScreen();

	for(uint i = 0; i < 20; ++i) {
		int r = skipEvents();
		if (r != 0)
			return r > 0? true: false;
		_system->delayMillis(100);
	}
	cdlogo.close();

	return true;
}
Exemple #8
0
Common::SeekableReadStream *MADSResourceManager::loadResource(const char *resourceName, bool loadFlag) {
	Common::File hagFile;
	uint32 offset = 0, size = 0;

	// If the first character is a '@' then look for an external file

	if (*resourceName == '@') {
		++resourceName;

		hagFile.open(resourceName);
		if (loadFlag)
			return hagFile.readStream(hagFile.size());
		else
			return new Common::SeekableSubReadStream(&hagFile, 0, hagFile.size());
	}

	// If the first character is the wildcard (resource indicator), skip over it
	if (*resourceName == '*')
		++resourceName;

	char resName[20];
	strcpy(resName, resourceName);
	str_upper(resName);

	hagFile.open(getResourceFilename(resName));

	// Validate hag file header
	char headerBuffer[16];
	if ((hagFile.read(headerBuffer, 16) != 16) || (strncmp(headerBuffer, madsConcatString, 10) != 0))
		error("Invalid HAG file opened");

	int numEntries = hagFile.readUint16LE();

	int resIndex = -1;
	while (++resIndex < numEntries) {
		// Read in the details of the next resource
		char resourceBuffer[14];
		offset = hagFile.readUint32LE();
		size = hagFile.readUint32LE();
		hagFile.read(resourceBuffer, 14);

		if (!strcmp(resName, resourceBuffer))
			break;
	}

	if (resIndex == numEntries)
		error("Invalid resource '%s' specified", resourceName);

	// Get the resource, either loading it in it's entirely or getting a stream reference

	if (loadFlag) {
		hagFile.seek(offset);
		return hagFile.readStream(size);
	} else {
		return new Common::SeekableSubReadStream(&hagFile, offset, offset + size);
	}
}
Exemple #9
0
/**
 * Loads the contents of the mort.dat data file
 */
Common::ErrorCode MortevielleEngine::loadMortDat() {
	Common::File f;

	// Open the mort.dat file
	if (!f.open(MORT_DAT)) {
		GUIErrorMessage("Could not locate 'mort.dat'.");
		return Common::kReadingFailed;
	}

	// Validate the data file header
	char fileId[4];
	f.read(fileId, 4);
	if (strncmp(fileId, "MORT", 4) != 0) {
		GUIErrorMessage("The located mort.dat data file is invalid");
		return Common::kReadingFailed;
	}

	// Check the version
	if (f.readByte() < MORT_DAT_REQUIRED_VERSION) {
		GUIErrorMessage("The located mort.dat data file is too old, please download an updated version on scummvm.org");
		return Common::kReadingFailed;
	}
	f.readByte();		// Minor version

	// Loop to load resources from the data file
	while (f.pos() < f.size()) {
		// Get the Id and size of the next resource
		char dataType[4];
		int dataSize;
		f.read(dataType, 4);
		dataSize = f.readUint16LE();

		if (!strncmp(dataType, "FONT", 4)) {
			// Font resource
			_screenSurface.readFontData(f, dataSize);
		} else if (!strncmp(dataType, "SSTR", 4)) {
			readStaticStrings(f, dataSize, kStaticStrings);
		} else if ((!strncmp(dataType, "GSTR", 4)) && (!_txxFileFl)) {
			readStaticStrings(f, dataSize, kGameStrings);
		} else if (!strncmp(dataType, "VERB", 4)) {
			_menu.readVerbNums(f, dataSize);
		} else {
			// Unknown section
			f.skip(dataSize);
		}
	}

	// Close the file
	f.close();

	assert(_engineStrings.size() > 0);
	return Common::kNoError;
}
Exemple #10
0
//Gets AGIPAL Data
void GfxMgr::setAGIPal(int p0) {
	//If 0 from savefile, do not use
	if (p0 == 0)
		return;

	char filename[15];
	sprintf(filename, "pal.%d", p0);

	Common::File agipal;
	if (!agipal.open(filename)) {
		warning("Couldn't open AGIPAL palette file '%s'. Not changing palette", filename);
		return; // Needed at least by Naturette 3 which uses AGIPAL but provides no palette files
	}

	//Chunk0 holds colors 0-7
	agipal.read(&_agipalPalette[0], 24);

	//Chunk1 is the same as the chunk0

	//Chunk2 chunk holds colors 8-15
	agipal.seek(24, SEEK_CUR);
	agipal.read(&_agipalPalette[24], 24);

	//Chunk3 is the same as the chunk2

	//Chunks4-7 are duplicates of chunks0-3

	if (agipal.eos() || agipal.err()) {
		warning("Couldn't read AGIPAL palette from '%s'. Not changing palette", filename);
		return;
	}

	// Use only the lowest 6 bits of each color component (Red, Green and Blue)
	// because VGA used only 6 bits per color component (i.e. VGA had 18-bit colors).
	// This should now be identical to the original AGIPAL-hack's behavior.
	bool validVgaPalette = true;
	for (int i = 0; i < 16 * 3; i++) {
		if (_agipalPalette[i] >= (1 << 6)) {
			_agipalPalette[i] &= 0x3F; // Leave only the lowest 6 bits of each color component
			validVgaPalette = false;
		}
	}

	if (!validVgaPalette)
		warning("Invalid AGIPAL palette (Over 6 bits per color component) in '%s'. Using only the lowest 6 bits per color component", filename);

	_agipalFileNum = p0;

	initPalette(_agipalPalette);
	gfxSetPalette();

	debug(1, "Using AGIPAL palette from '%s'", filename);
}
Exemple #11
0
/**
 * Speech function - Load Noise file
 * @remarks	Originally called 'charge_bruit'
 */
void SpeechManager::loadNoise() {
	Common::File f;

	if (!f.open("bruits"))               //Translation: "noise"
		error("Missing file - bruits");

	f.read(&_vm->_mem[kAdrNoise * 16], 250 * 128); // 32000
	for (int i = 0; i < _noise5Size; ++i)
		_vm->_mem[(kAdrNoise * 16) + 32000 + i] = _noise5Buf[i];
	f.read(&_vm->_mem[(kAdrNoise1 * 16) + kOffsetB1], 149 * 128); // 19072

	f.close();
}
Exemple #12
0
/**
 * Reads boot file for program environment.  Fatal error if not there or
 * file checksum is bad.  De-crypts structure while checking checksum
 */
void FileManager::readBootFile() {
	debugC(1, kDebugFile, "readBootFile()");

	Common::File ofp;
	if (!ofp.open(getBootFilename())) {
		if (_vm->_gameVariant == kGameVariantH1Dos) {
			//TODO initialize properly _boot structure
			warning("readBootFile - Skipping as H1 Dos may be a freeware");
			memset(_vm->_boot._distrib, '\0', sizeof(_vm->_boot._distrib));
			_vm->_boot._registered = kRegFreeware;
			return;
		} else if (_vm->getPlatform() == Common::kPlatformPC) {
			warning("readBootFile - Skipping as H2 and H3 Dos may be shareware");
			memset(_vm->_boot._distrib, '\0', sizeof(_vm->_boot._distrib));
			_vm->_boot._registered = kRegShareware;
			return;
		} else {
			Utils::notifyBox(Common::String::format("Missing startup file '%s'", getBootFilename()));
			_vm->getGameStatus()._doQuitFl = true;
			return;
		}
	}

	if (ofp.size() < (int32)sizeof(_vm->_boot)) {
		Utils::notifyBox(Common::String::format("Corrupted startup file '%s'", getBootFilename()));
		_vm->getGameStatus()._doQuitFl = true;
		return;
	}

	_vm->_boot._checksum = ofp.readByte();
	_vm->_boot._registered = ofp.readByte();
	ofp.read(_vm->_boot._pbswitch, sizeof(_vm->_boot._pbswitch));
	ofp.read(_vm->_boot._distrib, sizeof(_vm->_boot._distrib));
	_vm->_boot._exitLen = ofp.readUint16LE();

	byte *p = (byte *)&_vm->_boot;

	byte checksum = 0;
	for (uint32 i = 0; i < sizeof(_vm->_boot); i++) {
		checksum ^= p[i];
		p[i] ^= s_bootCypher[i % s_bootCypherLen];
	}
	ofp.close();

	if (checksum) {
		Utils::notifyBox(Common::String::format("Corrupted startup file '%s'", getBootFilename()));
		_vm->getGameStatus()._doQuitFl = true;
	}
}
Exemple #13
0
byte *Sword2Engine::fetchPsxBackground(uint32 location) {
	Common::File file;
	PSXScreensEntry header;
	uint32 screenOffset, dataOffset;
	uint32 totSize; // Total size of background, counting data, offset table and additional header
	byte *buffer;

	if (!file.open("screens.clu")) {
		GUIErrorMessage("Broken Sword 2: Cannot open screens.clu");
		return NULL;
	}

	file.seek(location * 4, SEEK_SET);
	screenOffset = file.readUint32LE();

	if (screenOffset == 0) { // We don't have screen data for this location number.
		file.close();
		return NULL;
	}

	// Get to the beginning of PSXScreensEntry
	file.seek(screenOffset + ResHeader::size(), SEEK_SET);

	buffer = (byte *)malloc(PSXScreensEntry::size());
	file.read(buffer, PSXScreensEntry::size());

	// Prepare the header
	header.read(buffer);
	free(buffer);

	file.seek(screenOffset + header.bgOffset + 4, SEEK_SET);
	dataOffset = file.readUint32LE();

	file.seek(screenOffset + header.bgOffset, SEEK_SET);

	totSize = header.bgSize + (dataOffset - header.bgOffset) + 8;
	buffer = (byte *)malloc(totSize);

	// Write some informations before background data
	WRITE_LE_UINT16(buffer, header.bgXres);
	WRITE_LE_UINT16(buffer + 2, header.bgYres);
	WRITE_LE_UINT32(buffer + 4, header.bgOffset);

	file.read(buffer + 8, totSize - 8); // Do not write on the header
	file.close();

	return buffer;
}
Exemple #14
0
int AgiEngine::loadWords(const char *fname) {
	Common::File fp;
	uint32 flen;
	uint8 *mem = NULL;

	words = NULL;

	if (!fp.open(fname)) {
		warning("loadWords: can't open %s", fname);
		return errOK; // err_BadFileOpen
	}
	debug(0, "Loading dictionary: %s", fname);

	fp.seek(0, SEEK_END);
	flen = fp.pos();
	wordsFlen = flen;
	fp.seek(0, SEEK_SET);

	if ((mem = (uint8 *)calloc(1, flen + 32)) == NULL) {
		fp.close();
		return errNotEnoughMemory;
	}

	fp.read(mem, flen);
	fp.close();

	words = mem;

	return errOK;
}
Exemple #15
0
/**
 * Read the encrypted text from the boot file and print it
 */
void FileManager::printBootText() {
	debugC(1, kDebugFile, "printBootText()");

	Common::File ofp;
	if (!ofp.open(getBootFilename())) {
		if (_vm->_gameVariant == kGameVariantH1Dos) {
			//TODO initialize properly _boot structure
			warning("printBootText - Skipping as H1 Dos may be a freeware");
			return;
		} else {
			error("Missing startup file '%s'", getBootFilename());
		}
	}

	// Allocate space for the text and print it
	char *buf = (char *)malloc(_vm->_boot.exit_len + 1);
	if (buf) {
		// Skip over the boot structure (already read) and read exit text
		ofp.seek((long)sizeof(_vm->_boot), SEEK_SET);
		if (ofp.read(buf, _vm->_boot.exit_len) != (size_t)_vm->_boot.exit_len)
			error("Error while reading startup file");

		// Decrypt the exit text, using CRYPT substring
		int i;
		for (i = 0; i < _vm->_boot.exit_len; i++)
			buf[i] ^= s_bootCyper[i % s_bootCyperLen];

		buf[i] = '\0';
		Utils::notifyBox(buf);
	}

	free(buf);
	ofp.close();
}
Exemple #16
0
// Dumps all of the game's music in external XMIDI *.xmi files
void dumpMusic() {
	Common::File midiFile;
	Common::DumpFile outFile;
	char outName[20];
	midiFile.open(MIDI_FILE);
	int outFileSize = 0;
	char buffer[20000];

	const int total = 155;	// maximum (SCN version)

	for (int i = 0; i < total; i++) {
		if (midiOffsets[i] == 0)
			break;

		sprintf(outName, "track%03d.xmi", i + 1);
		outFile.open(outName);

		if (i < total - 1)
			outFileSize = midiOffsets[i + 1] - midiOffsets[i] - 4;
		else
			outFileSize = midiFile.size() - midiOffsets[i] - 4;

		midiFile.seek(midiOffsets[i] + 4, SEEK_SET);

		assert(outFileSize < 20000);
		midiFile.read(buffer, outFileSize);
		outFile.write(buffer, outFileSize);

		outFile.close();
	}

	midiFile.close();
}
Exemple #17
0
int AgiEngine::loadObjects(const char *fname) {
	Common::File fp;
	uint32 flen;
	uint8 *mem;

	_objects = NULL;
	_game.numObjects = 0;

	debugC(5, kDebugLevelResources, "(Loading objects '%s')", fname);

	if (!fp.open(fname))
		return errBadFileOpen;

	fp.seek(0, SEEK_END);
	flen = fp.pos();
	fp.seek(0, SEEK_SET);

	if ((mem = (uint8 *)calloc(1, flen + 32)) == NULL) {
		fp.close();
		return errNotEnoughMemory;
	}

	fp.read(mem, flen);
	fp.close();

	decodeObjects(mem, flen);
	free(mem);
	return errOK;
}
Exemple #18
0
bool Debugger::Cmd_DumpFile(int argc, const char **argv) {
    if (argc != 2) {
        debugPrintf("Usage: %s <resource>\n", argv[0]);
    } else {
        Common::DumpFile outFile;
        Common::File inFile;

        if (!inFile.open(argv[1])) {
            debugPrintf("Specified resource does not exist\n");
        } else {
            outFile.open(argv[1]);
            byte *data = new byte[inFile.size()];

            inFile.read(data, inFile.size());
            outFile.write(data, inFile.size());
            outFile.flush();

            delete[] data;
            inFile.close();
            outFile.close();

            debugPrintf("File written successfully.\n");
        }
    }

    return true;
}
Exemple #19
0
ZorkCursor::ZorkCursor(const Common::String &fileName)
    : _width(0),
      _height(0),
      _hotspotX(0),
      _hotspotY(0) {
    Common::File file;
    if (!file.open(fileName))
        return;

    uint32 magic = file.readUint32BE();
    if (magic != MKTAG('Z', 'C', 'R', '1')) {
        warning("%s is not a Zork Cursor file", fileName.c_str());
        return;
    }

    _hotspotX = file.readUint16LE();
    _hotspotY = file.readUint16LE();
    _width = file.readUint16LE();
    _height = file.readUint16LE();

    uint dataSize = _width * _height * sizeof(uint16);
    _surface.create(_width, _height, Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0));
    uint32 bytesRead = file.read(_surface.getPixels(), dataSize);
    assert(bytesRead == dataSize);

    // Convert to RGB 565
    _surface.convertToInPlace(Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0));
}
Exemple #20
0
/**
 * Read uif item into supplied buffer.
 */
void FileManager::readUIFItem(const int16 id, byte *buf) {
	debugC(1, kDebugFile, "readUIFItem(%d, ...)", id);

	// Open uif file to read data
	Common::File ip;                                // UIF_FILE handle
	if (!ip.open(getUifFilename()))
		error("File not found: %s", getUifFilename());

	// Seek to data
	UifHdr *_UIFHeaderPtr = getUIFHeader((Uif)id);
	ip.seek(_UIFHeaderPtr->_offset, SEEK_SET);

	// We support pcx images and straight data
	Seq *dummySeq;                                // Dummy Seq for image data
	switch (id) {
	case UIF_IMAGES:                                // Read uif images file
		dummySeq = readPCX(ip, 0, buf, true, getUifFilename());
		free(dummySeq);
		break;
	default:                                        // Read file data into supplied array
		if (ip.read(buf, _UIFHeaderPtr->_size) != _UIFHeaderPtr->_size)
			error("Wrong UIF file format");
		break;
	}

	ip.close();
}
Exemple #21
0
Common::SeekableReadStream *CCArchive::createReadStreamForMember(const Common::String &name) const {
	CCEntry ccEntry;

	if (getHeaderEntry(name, ccEntry)) {
		// Open the correct CC file
		Common::File f;
		if (!f.open(_filename))
			error("Could not open CC file");

		// Read in the data for the specific resource
		f.seek(ccEntry._offset);
		byte *data = (byte *)malloc(ccEntry._size);
		f.read(data, ccEntry._size);

		if (_encoded) {
			// Decrypt the data
			for (int i = 0; i < ccEntry._size; ++i)
				data[i] ^= 0x35;
		}

		// Return the data as a stream
		return new Common::MemoryReadStream(data, ccEntry._size, DisposeAfterUse::YES);
	}

	return nullptr;
}
void writeSoundNames(const char *sourceFilename, Common::File &target, uint offset) {
	Common::File source;
	if (!source.open(sourceFilename)) {
		error("Unable to open '%s'", sourceFilename);
	}

	source.seek(offset);

	// Count the sounds
	uint count = 0;
	while (1) {
		uint32 id = source.readUint32LE();

		if (!id)
			break;

		source.skip(32);
		count++;
	}

	target.writeLong(count);

	source.seek(offset);
	for (uint i = 0; i < count; i++) {
		uint32 id = source.readUint32LE();
		char name[32];
		source.read(name, sizeof(name));

		target.writeLong(id);
		target.write(name, sizeof(name));
	}

	source.close();
}
Exemple #23
0
Localizer::Localizer() {
	Common::File f;
	const char *namesToTry[] = { "GRIM.TAB", "Grim.tab", "grim.tab" };

	if (g_grim->getGameFlags() & GF_DEMO)
		return;

	for (unsigned i = 0; i < sizeof(namesToTry) / sizeof(namesToTry[0]); i++) {
		f.open(namesToTry[i]);
		if (f.isOpen())
			break;
	}
	if (!f.isOpen()) {
		error("Localizer::Localizer: Unable to find localization information (grim.tab)");
		return;
	}

	long filesize = f.size();

	// Read in the data
	char *data = new char[filesize + 1];
	f.read(data, filesize);
	data[filesize] = '\0';
	f.close();

	if (filesize < 4 || READ_BE_UINT32(data) != MKID_BE('RCNE'))
		error("Invalid magic reading grim.tab");

	// Decode the data
	for (int i = 4; i < filesize; i++)
		data[i] ^= '\xdd';

	char *nextline;
	for (char *line = data + 4; line != NULL && *line != '\0'; line = nextline) {
		nextline = strchr(line, '\n');

		if (nextline) {
			if (nextline[-1] == '\r')
				nextline[-1] = '\0';
			nextline++;
		}
		char *tab = strchr(line, '\t');

		if (!tab)
			continue;

		LocaleEntry entry;
		entry.text = new char[(tab - line) + 1];
		strncpy(entry.text, line, tab - line);
		entry.text[tab - line] = '\0';
		entry.translation = new char[strlen(tab + 1) + 1];
		strcpy(entry.translation, tab + 1);
		_entries.push_back(entry);
	}

	qsort(_entries.begin(), _entries.size(), sizeof(LocaleEntry), sortCallback);

	delete[] data;
}
Exemple #24
0
void MainMenu::loadFont() {
    Common::File file;
    if (!file.open("avalot.fnt"))
        error("AVALANCHE: Scrolls: File not found: avalot.fnt");
    for (int16 i = 0; i < 256; i++)
        file.read(_font[i], 16);
    file.close();
}
void copyData(Common::File &temp, Common::File &target) {
	uint dataSize = temp.size();
	byte *data = new byte[dataSize];

	temp.seek(0);
	temp.read(data, dataSize);
	target.write(data, dataSize);

	delete[] data;
}
Exemple #26
0
void Troll::init() {
    _vm->_picture->setPictureVersion(AGIPIC_V15);
    //SetScreenPar(320, 200, (char*)ibm_fontdata);

    const int gaps[] = { 0x3A40,  0x4600,  0x4800,  0x5800,  0x5a00,  0x6a00,
                         0x6c00,  0x7400,  0x7600,  0x7c00,  0x7e00,  0x8e00,
                         0x9000,  0xa000,  0xa200,  0xb200,  0xb400,  0xc400,
                         0xc600,  0xd600,  0xd800,  0xe800,  0xea00,  0xfa00,
                         0xfc00,  0x10c00, 0x10e00, 0x11e00, 0x12000, 0x13000
                       };

    Common::File infile;
    if (!infile.open(IDA_TRO_BINNAME))
        return;

    _gameData = (byte *)malloc(0xD9C0);

    bool flip = true;
    byte *ptr = _gameData;
    int diff;

    for (int i = 0; i < ARRAYSIZE(gaps) - 1; i++) {
        diff = gaps[i + 1] - gaps[i];

        if (flip) {
            infile.seek(gaps[i]);
            infile.read(ptr, diff);
            ptr += diff;
        } else {
        }
        flip = !flip;
    }

    // One sector is off
    infile.seek(0x18470);
    infile.read(_gameData + 15632, 592);

    infile.close();

    fillOffsets();
}
Exemple #27
0
TextFont *Resource::getFont(const Common::String fileName) {
	// TODO: Add support for the font format of the Amiga version
	Common::File *dataFile = openDataFile(fileName, MKTAG('V', 'G', 'A', 'F'));

	uint32 headerSize = 4 + 2 + 256 * 3 + 4;
	uint32 fileSize = dataFile->size();
	if (fileSize <= headerSize)
		return nullptr;

	TextFont *textfont = new TextFont();
	textfont->_dataLength = fileSize - headerSize;
	textfont->_height = dataFile->readUint16LE();
	dataFile->read(textfont->_widths, 256);
	for (int i = 0; i < 256; i++)
		textfont->_offsets[i] = dataFile->readUint16LE();
	dataFile->skip(4);
	textfont->_data = new byte[textfont->_dataLength + 4];
	dataFile->read(textfont->_data, textfont->_dataLength);
	delete dataFile;
	return textfont;
}
Exemple #28
0
bool Script::loadScript(Common::String filename) {
	// Try to open the script file
	Common::File scriptfile;
	if (!scriptfile.open(filename)) {
		return false;
	}

	// Save the script filename
	_scriptFile = filename;

	// Load the code
	_codeSize = scriptfile.size();
	_code = new byte[_codeSize];
	if (!_code)
		return false;
	scriptfile.read(_code, _codeSize);
	scriptfile.close();

	// Patch the loaded code for known script bugs
	if (filename.equals("dr.grv")) {
		// WORKAROUND for the cake puzzle glitch (bug #2458322): Lowering the
		// piece on the first column and second row updates the wrong script
		// variable
		assert(_codeSize == 5546);
		_code[0x03C2] = 0x38;
	} else if (filename.equals("maze.grv")) {
		// GRAPHICS ENHANCEMENT - Leave a skeleton in the maze.
		// Replaces one normal T intersection with the unused(?)
		// skeleton T intersection graphics.
		assert(_codeSize == 3652);

		// Terminating T branch
		_code[0x0769] = 0x46;
		_code[0x0774] = 0x3E;
		_code[0x077A] = 0x42;

		// T with branch on right
		_code[0x08E2] = 0x43;
		_code[0x08D7] = 0x44;
		_code[0x08E8] = 0x45;

		// T with branch on left
		_code[0x0795] = 0x41;
		_code[0x078A] = 0x40;
		_code[0x079B] = 0x3F;
	}

	// Initialize the script
	_currentInstruction = 0;

	return true;
}
Exemple #29
0
bool CruiseEngine::loadLanguageStrings() {
	Common::File f;

	// Give preference to a language file
	if (f.open("DELPHINE.LNG")) {
		char *data = (char *)MemAlloc(f.size());
		f.read(data, f.size());
		char *ptr = data;

		for (int i = 0; i < MAX_LANGUAGE_STRINGS; ++i) {
			// Get the start of the next string
			while (*ptr != '"') ++ptr;
			const char *v = ++ptr;

			// Find the end of the string, and replace the end '"' with a NULL
			while (*ptr != '"') ++ptr;
			*ptr++ = '\0';

			// Add the string to the list
			_langStrings.push_back(v);
		}

		f.close();
		MemFree(data);

	} else {
		// Try and use one of the pre-defined language lists
		const char **p = NULL;
		switch (getLanguage()) {
		case Common::EN_ANY:
			p = englishLanguageStrings;
			break;
		case Common::FR_FRA:
			p = frenchLanguageStrings;
			break;
		case Common::DE_DEU:
			p = germanLanguageStrings;
			break;
		case Common::IT_ITA:
			p = italianLanguageStrings;
			break;
		default:
			return false;
		}

		// Load in the located language set
		for (int i = 0; i < 13; ++i, ++p)
			_langStrings.push_back(*p);
	}

	return true;
}
Exemple #30
0
/**
 * Load sonmus.mor file
 * @remarks	Originally called 'charge_son'
 */
void SpeechManager::loadMusicSound() {
	Common::File f;
	if (!f.open("sonmus.mor"))
		error("Missing file - sonmus.mor");

	free(_vm->_compMusicBuf1);
	int size = f.size();
	_vm->_compMusicBuf1 = (byte *)malloc(sizeof(byte) * size);
	f.read(_vm->_compMusicBuf1, size);

	_vm->_soundManager.decodeMusic(_vm->_compMusicBuf1, &_vm->_mem[kAdrNoise * 16], size);
	f.close();
}