int main(int argc, char *argv[]) { if (argc != 3) { printf("Format: %s ST.exe titanic.dat\n", argv[0]); exit(0); } if (!inputFile.open(argv[1])) { error("Could not open input file"); } res.loadFromEXE(argv[1]); if (inputFile.size() == ENGLISH_10042C_FILESIZE) _version = ENGLISH_10042C; else if (inputFile.size() == ENGLISH_10042B_FILESIZE) _version = ENGLISH_10042B; else if (inputFile.size() == ENGLISH_10042_FILESIZE) _version = ENGLISH_10042; else { printf("Unknown version of ST.exe specified"); exit(0); } if (!outputFile.open(argv[2], Common::kFileWriteMode)) { error("Could not open output file"); } writeHeader(); writeData(); writeFinalEntryHeader(); inputFile.close(); outputFile.close(); return 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; }
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; }
// 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"); } }
int main(int argc, char *argv[]) { if (argc < 2) { printf("Usage: %s [exe folder]\n", argv[0]); printf("Where [exe folder] contains the following files:\n"); printf("- M3_EN_127.exe: English v1.27 Window binary from the DVD release\n"); printf("- M3_FR_122.exe: French v1.22 Window binary from the update patch\n"); printf("- M3_FR_122.exe: English v1.22 Window binary from the update patch\n"); printf("- M3_XBOX_PAL.xbe: PAL XBox binary\n"); printf("- M3_XBOX_NTSC.xbe: NTSC XBox binary\n"); return -1; } std::string path = argv[1]; std::string dvdExe = path + "M3_EN_127.exe"; std::string cdIntlExe = path + "M3_FR_122.exe"; std::string cdEnglishExe = path + "M3_EN_122.exe"; std::string xboxPalExe = path + "M3_XBOX_PAL.xbe"; std::string xboxNtscExe = path + "M3_XBOX_NTSC.xbe"; Common::File temp; if (!temp.open("data.tmp", Common::kFileWriteMode)) { error("Unable to open '%s'", "data.tmp"); } writeScriptData(dvdExe.c_str(), temp, roomScripts, ARRAYSIZE(roomScripts)); writeScriptData(dvdExe.c_str(), temp, menuScriptsDvd, ARRAYSIZE(menuScriptsDvd)); writeScriptData(cdIntlExe.c_str(), temp, menuScriptsCdIntl, ARRAYSIZE(menuScriptsCdIntl)); writeScriptData(cdEnglishExe.c_str(), temp, menuScriptsCdEnglish, ARRAYSIZE(menuScriptsCdEnglish)); writeScriptData(xboxPalExe.c_str(), temp, roomScriptsXBox, ARRAYSIZE(roomScriptsXBox)); writeScriptData(xboxPalExe.c_str(), temp, menuScriptsXboxIntl, ARRAYSIZE(menuScriptsXboxIntl)); writeScriptData(xboxNtscExe.c_str(), temp, menuScriptsXboxEnglish, ARRAYSIZE(menuScriptsXboxEnglish)); Common::File target; if (!target.open("myst3.dat", Common::kFileWriteMode)) { error("Unable to open '%s'", "myst3.dat"); } target.writeLong(MKTAG('M', 'Y', 'S', 'T')); target.writeLong(kVersion); writeScriptIndex(target, roomScripts, ARRAYSIZE(roomScripts)); writeScriptIndex(target, menuScriptsDvd, ARRAYSIZE(menuScriptsDvd)); writeScriptIndex(target, menuScriptsCdIntl, ARRAYSIZE(menuScriptsCdIntl)); writeScriptIndex(target, menuScriptsCdEnglish, ARRAYSIZE(menuScriptsCdEnglish)); writeScriptIndex(target, roomScriptsXBox, ARRAYSIZE(roomScriptsXBox)); writeScriptIndex(target, menuScriptsXboxIntl, ARRAYSIZE(menuScriptsXboxIntl)); writeScriptIndex(target, menuScriptsXboxEnglish, ARRAYSIZE(menuScriptsXboxEnglish)); writeSoundNames(dvdExe.c_str(), target, 549360); writeSoundNames(xboxPalExe.c_str(), target, 913960); copyData(temp, target); temp.close(); target.close(); return 0; }
/** * Read and decode objects, and store them in the internal structure. * * @param fp File pointer * @param flen File length */ int AgiEngine::readObjects(Common::File &fp, int flen) { uint8 *mem; 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; }
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; }
/** * 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; }
void CompressGob::execute() { Common::File stk; Common::File gobConf; uint16 chunkCount; Common::Filename inpath(_inputPaths[0].path); // We output with .stk extension, if there is no specific out file if (_outputPath.empty()) { _outputPath = inpath; } // Open input (config) file gobConf.open(inpath, "r"); // Read the input into memory _chunks = readChunkConf(gobConf, inpath, chunkCount); gobConf.close(); _outputPath.setFullName(inpath.getFullName()); stk.open(_outputPath, "wb"); // Output in compressed format writeEmptyHeader (stk, chunkCount); writeBody(&inpath, stk, _chunks); rewriteHeader(stk, chunkCount, _chunks); }
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; }
void Lingo::runTests() { Common::File inFile; Common::ArchiveMemberList fileList; SearchMan.listMatchingMembers(fileList, "*.lingo"); int counter = 1; for (Common::ArchiveMemberList::iterator it = fileList.begin(); it != fileList.end(); ++it) { Common::ArchiveMember const &m = **it; Common::SeekableReadStream *const stream = m.createReadStream(); if (stream) { uint size = stream->size(); char *script = (char *)calloc(size + 1, 1); stream->read(script, size); warning("Compiling file %s of size %d, id: %d", m.getName().c_str(), size, counter); _hadError = false; addCode(script, kMovieScript, counter); if (!_hadError) executeScript(kMovieScript, counter); else warning("Skipping execution"); free(script); counter++; } inFile.close(); } }
void MoviePlayerDXA::readSoundData(Common::SeekableReadStream *stream) { uint32 tag = stream->readUint32BE(); if (tag == MKTAG('W','A','V','E')) { uint32 size = stream->readUint32BE(); if (_sequenceNum) { Common::File in; stream->skip(size); in.open("audio.wav"); if (!in.isOpen()) { error("Can't read offset file 'audio.wav'"); } in.seek(_sequenceNum * 8, SEEK_SET); uint32 offset = in.readUint32LE(); size = in.readUint32LE(); in.seek(offset, SEEK_SET); _bgSoundStream = Audio::makeWAVStream(in.readStream(size), DisposeAfterUse::YES); in.close(); } else { _bgSoundStream = Audio::makeWAVStream(stream->readStream(size), DisposeAfterUse::YES); } } else { _bgSoundStream = Audio::SeekableAudioStream::openStreamFile(baseName); } }
/** * 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(); }
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 }
// 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(); }
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; }
void SndRes::setVoiceBank(int serial) { Common::File *file; if (_voiceSerial == serial) return; #ifdef ENABLE_IHNM // If we got the Macintosh version of IHNM, just set the voice bank // so that we know which voices* subfolder to look for later if (_vm->getGameId() == GID_IHNM && _vm->isMacResources()) { _voiceSerial = serial; // Set a dummy voice context _voiceContext = new VoiceResourceContext_RES(); return; } #endif // If there are no voice files present, don't set the voice bank if (!_vm->_voiceFilesExist) return; // Close previous voice bank file if (_voiceContext != NULL) { file = _voiceContext->getFile(NULL); if (file->isOpen()) { file->close(); } } _voiceSerial = serial; _voiceContext = _vm->_resource->getContext(GAME_VOICEFILE, _voiceSerial); }
void MoviePlayerDXA::startSound() { uint32 offset, size; if (getSoundTag() == MKID_BE('WAVE')) { size = _fileStream->readUint32BE(); if (_sequenceNum) { Common::File in; _fileStream->seek(size, SEEK_CUR); in.open((const char *)"audio.wav"); if (!in.isOpen()) { error("Can't read offset file 'audio.wav'"); } in.seek(_sequenceNum * 8, SEEK_SET); offset = in.readUint32LE(); size = in.readUint32LE(); in.seek(offset, SEEK_SET); _bgSoundStream = Audio::makeWAVStream(in.readStream(size), DisposeAfterUse::YES); in.close(); } else { _bgSoundStream = Audio::makeWAVStream(_fileStream->readStream(size), DisposeAfterUse::YES); } } else { _bgSoundStream = Audio::SeekableAudioStream::openStreamFile(baseName); } if (_bgSoundStream != NULL) { _vm->_mixer->stopHandle(_bgSound); _vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, &_bgSound, _bgSoundStream); } }
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; }
void SoundHE::setupHEMusicFile() { int i, total_size; Common::File musicFile; Common::String buf(_vm->generateFilename(-4)); if (musicFile.open(buf) == true) { musicFile.seek(4, SEEK_SET); total_size = musicFile.readUint32BE(); musicFile.seek(16, SEEK_SET); _heMusicTracks = musicFile.readUint32LE(); debug(5, "Total music tracks %d", _heMusicTracks); int musicStart = (_vm->_game.heversion >= 80) ? 56 : 20; musicFile.seek(musicStart, SEEK_SET); _heMusic = (HEMusic *)malloc((_heMusicTracks + 1) * sizeof(HEMusic)); for (i = 0; i < _heMusicTracks; i++) { _heMusic[i].id = musicFile.readUint32LE(); _heMusic[i].offset = musicFile.readUint32LE(); _heMusic[i].size = musicFile.readUint32LE(); if (_vm->_game.heversion >= 80) { musicFile.seek(+9, SEEK_CUR); } else { musicFile.seek(+13, SEEK_CUR); } } musicFile.close(); } }
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(); }
void MemoryBlock::saveToFile(const Common::String &filename) { Common::File *f = new Common::File(); f->open(filename.c_str(), Common::File::kFileWriteMode); f->write(_data, _size); f->close(); delete f; }
Common::SeekableReadStream *Resources::load(const Common::String &filename) { // First check if the file is directly in the cache if (_cache.isCached(filename)) return _cache.get(filename); // Secondly, iterate through any loaded library file looking for a resource // that has the same name for (LibraryIndexes::iterator i = _indexes.begin(); i != _indexes.end(); ++i) { if (i->_value.contains(filename)) { // Get a stream reference to the given library file Common::SeekableReadStream *stream = load(i->_key); LibraryEntry &entry = i->_value[filename]; _resourceIndex = entry._index; stream->seek(entry._offset); Common::SeekableReadStream *resStream = stream->readStream(entry._size); decompressIfNecessary(resStream); delete stream; return resStream; } } // At this point, fall back on a physical file with the given name Common::File f; if (!f.open(filename)) error("Could not load file - %s", filename.c_str()); Common::SeekableReadStream *stream = f.readStream(f.size()); f.close(); decompressIfNecessary(stream); return stream; }
/** * 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; }
/** * 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(); }
bool GlulxeMetaEngine::detectGames(const Common::FSList &fslist, DetectedGames &gameList) { const char *const EXTENSIONS[3] = { ".ulx", ".blb", ".gblorb" }; // Loop through the files of the folder for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { // Check for a recognised filename if (file->isDirectory()) continue; Common::String filename = file->getName(); bool hasExt = false; for (int idx = 0; idx < 3 && !hasExt; ++idx) hasExt = filename.hasSuffixIgnoreCase(EXTENSIONS[idx]); if (!hasExt) continue; // Open up the file and calculate the md5 Common::File gameFile; if (!gameFile.open(*file)) continue; Common::String md5 = Common::computeStreamMD5AsString(gameFile, 5000); size_t filesize = gameFile.size(); gameFile.close(); // Check for known games const GlulxeGameDescription *p = GLULXE_GAMES; while (p->_gameId && (md5 != p->_md5 || filesize != p->_filesize)) ++p; DetectedGame gd; if (!p->_gameId) { if (filename.hasSuffixIgnoreCase(".blb")) continue; if (gDebugLevel > 0) { // Print an entry suitable for putting into the detection_tables.h, using the // name of the parent folder the game is in as the presumed game Id Common::String folderName = file->getParent().getName(); if (folderName.hasSuffix("\\")) folderName.deleteLastChar(); Common::String fname = filename; const char *dot = strchr(fname.c_str(), '.'); if (dot) fname = Common::String(fname.c_str(), dot); debug("ENTRY0(\"%s\", \"%s\", %u),", fname.c_str(), md5.c_str(), (uint)filesize); } const PlainGameDescriptor &desc = GLULXE_GAME_LIST[0]; gd = DetectedGame(desc.gameId, desc.description, Common::UNK_LANG, Common::kPlatformUnknown); } else { PlainGameDescriptor gameDesc = findGame(p->_gameId); gd = DetectedGame(p->_gameId, gameDesc.description, p->_language, Common::kPlatformUnknown, p->_extra); gd.setGUIOptions(GUIO4(GUIO_NOSPEECH, GUIO_NOSFX, GUIO_NOMUSIC, GUIO_NOSUBTITLES)); } gd.addExtraEntry("filename", filename); gameList.push_back(gd); } return !gameList.empty(); }
Audio::RewindableAudioStream *makeRawZorkStream(const Common::String &filePath, ZVision *engine) { Common::File *file = new Common::File(); Common::String actualName = filePath; bool found = engine->getSearchManager()->openFile(*file, actualName); bool isRaw = actualName.hasSuffix(".raw"); if ((!found && isRaw) || (found && isRaw && file->size() < 10)) { if (found) file->close(); // Check for an audio patch (.src) actualName.setChar('s', actualName.size() - 3); actualName.setChar('r', actualName.size() - 2); actualName.setChar('c', actualName.size() - 1); if (!engine->getSearchManager()->openFile(*file, actualName)) return NULL; } else if (!found && !isRaw) { return NULL; } // Get the file name Common::StringTokenizer tokenizer(actualName, "/\\"); Common::String fileName; while (!tokenizer.empty()) { fileName = tokenizer.nextToken(); } fileName.toLowercase(); const SoundParams *soundParams = NULL; if (engine->getGameId() == GID_NEMESIS) { for (int i = 0; i < 32; ++i) { if (RawZorkStream::_zNemSoundParamLookupTable[i].identifier == (fileName[6])) soundParams = &RawZorkStream::_zNemSoundParamLookupTable[i]; } } else if (engine->getGameId() == GID_GRANDINQUISITOR) { for (int i = 0; i < 24; ++i) { if (RawZorkStream::_zgiSoundParamLookupTable[i].identifier == (fileName[7])) soundParams = &RawZorkStream::_zgiSoundParamLookupTable[i]; } } if (soundParams == NULL) return NULL; if (soundParams->packed) { return makeRawZorkStream(wrapBufferedSeekableReadStream(file, 2048, DisposeAfterUse::YES), soundParams->rate, soundParams->stereo, DisposeAfterUse::YES); } else { byte flags = 0; if (soundParams->bits16) flags |= Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN; if (soundParams->stereo) flags |= Audio::FLAG_STEREO; return Audio::makePCMStream(file, soundParams->rate, flags, DisposeAfterUse::YES); } }
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; }
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 FrotzScreen::loadExtraFonts(Common::Archive *archive) { Image::BitmapDecoder decoder; Common::File f; if (!f.open("infocom_graphics.bmp", *archive)) error("Could not load font"); Common::Point fontSize(_fonts[0]->getMaxCharWidth(), _fonts[0]->getFontHeight()); decoder.loadStream(f); _fonts.push_back(new FixedWidthBitmapFont(*decoder.getSurface(), fontSize)); f.close(); // Add Runic font. It provides cleaner versions of the runic characters in the // character graphics font if (!f.open("NotoSansRunic-Regular.ttf", *archive)) error("Could not load font"); _fonts.push_back(Graphics::loadTTFFont(f, g_conf->_propInfo._size, Graphics::kTTFSizeModeCharacter)); f.close(); }