// AUDIOnnn.MAP contains 10-byte entries: // Early format: // w 5 bits resource type and 11 bits resource number // dw 7 bits volume number and 25 bits offset // dw size // Later format: // w nEntry // dw offset+volume (as in resource.map) // dw size // ending with 10 0xFFs int ResourceManager::readAudioMapSCI1(ResourceSource *map, bool unload) { Common::File file; if (!file.open(map->getLocationName())) return SCI_ERROR_RESMAP_NOT_FOUND; bool oldFormat = (file.readUint16LE() >> 11) == kResourceTypeAudio; file.seek(0); while (1) { uint16 n = file.readUint16LE(); uint32 offset = file.readUint32LE(); uint32 size = file.readUint32LE(); if (file.eos() || file.err()) { warning("Error while reading %s", map->getLocationName().c_str()); return SCI_ERROR_RESMAP_NOT_FOUND; } if (n == 0xffff) break; byte volume_nr; if (oldFormat) { n &= 0x07ff; // Mask out resource type volume_nr = offset >> 25; // most significant 7 bits offset &= 0x01ffffff; // least significant 25 bits } else { volume_nr = offset >> 28; // most significant 4 bits offset &= 0x0fffffff; // least significant 28 bits } ResourceSource *src = findVolume(map, volume_nr); if (src) { if (unload) removeAudioResource(ResourceId(kResourceTypeAudio, n)); else addResource(ResourceId(kResourceTypeAudio, n), src, offset, size); } else { warning("Failed to find audio volume %i", volume_nr); } }
void AGOSEngine::playMusic(uint16 music, uint16 track) { stopMusic(); if (getPlatform() == Common::kPlatformAmiga) { playModule(music); } else if (getPlatform() == Common::kPlatformAtariST) { // TODO: Add support for music formats used } else { _midi.setLoop(true); // Must do this BEFORE loading music. char filename[15]; Common::File f; sprintf(filename, "MOD%d.MUS", music); f.open(filename); if (f.isOpen() == false) error("playMusic: Can't load music from '%s'", filename); _midi.loadS1D(&f); _midi.startTrack(0); _midi.startTrack(track); } }
void TopMenu::loadBmpArr(Common::File &in) { arraySize = in.readUint16BE(); delete arrayBmp; arrayBmp = new Graphics::Surface *[arraySize * 2]; for (int i = 0; i < arraySize; i++) { uint16 bmpSize = in.readUint16BE(); uint32 filPos = in.pos(); Common::SeekableSubReadStream stream(&in, filPos, filPos + bmpSize); arrayBmp[i * 2] = Graphics::ImageDecoder::loadFile(stream, g_system->getOverlayFormat()); arrayBmp[i * 2 + 1] = new Graphics::Surface(); arrayBmp[i * 2 + 1]->create(arrayBmp[i * 2]->w * 2, arrayBmp[i * 2]->h * 2, arrayBmp[i * 2]->bytesPerPixel); byte *src = (byte *)arrayBmp[i * 2]->pixels; byte *dst = (byte *)arrayBmp[i * 2 + 1]->pixels; for (int j = 0; j < arrayBmp[i * 2]->h; j++) { src = (byte *)arrayBmp[i * 2]->getBasePtr(0, j); dst = (byte *)arrayBmp[i * 2 + 1]->getBasePtr(0, j * 2); for (int k = arrayBmp[i * 2]->w; k > 0; k--) { for (int m = arrayBmp[i * 2]->bytesPerPixel; m > 0; m--) { *dst++ = *src++; } src -= arrayBmp[i * 2]->bytesPerPixel; for (int m = arrayBmp[i * 2]->bytesPerPixel; m > 0; m--) { *dst++ = *src++; } } src = (byte *)arrayBmp[i * 2 + 1]->getBasePtr(0, j * 2); dst = (byte *)arrayBmp[i * 2 + 1]->getBasePtr(0, j * 2 + 1); for (int k = arrayBmp[i * 2 + 1]->pitch; k > 0; k--) { *dst++ = *src++; } } in.skip(bmpSize); } }
//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); }
void writeStarfieldPoints2() { outputFile.seek(dataOffset); const int OFFSETS[3] = { 0x5A2F28, 0x5A2CC8, 0x5A1CF8 }; for (int rootCtr = 0; rootCtr < 80; ++rootCtr) { inputFile.seek(OFFSETS[_version] - FILE_DIFF[_version] + rootCtr * 8); uint offset = inputFile.readUint32LE(); uint count = inputFile.readUint32LE(); outputFile.writeLong(count); inputFile.seek(offset - FILE_DIFF[_version]); outputFile.write(inputFile, count * 4 * 4); } uint size = outputFile.size() - dataOffset; outputFile.write(inputFile, size); writeEntryHeader("STARFIELD/POINTS2", dataOffset, size); dataOffset += size; }
void World::loadExternalSounds(Common::String fname) { Common::File in; in.open(fname); if (!in.isOpen()) { warning("Cannot load sound file <%s>", fname.c_str()); return; } in.close(); Common::MacResManager resMan; resMan.open(fname); Common::MacResIDArray resArray; Common::SeekableReadStream *res; Common::MacResIDArray::const_iterator iter; resArray = resMan.getResIDArray(MKTAG('A','S','N','D')); for (iter = resArray.begin(); iter != resArray.end(); ++iter) { res = resMan.getResource(MKTAG('A','S','N','D'), *iter); addSound(new Sound(resMan.getResName(MKTAG('A','S','N','D'), *iter), res)); } }
Common::SeekableReadStream *ERFFile::getResource(uint32 index) const { const IResource &res = getIResource(index); if (res.unpackedSize == 0) return new Common::MemoryReadStream(0, 0); if (_flags & 0xF0) throw Common::Exception("Unhandled ERF encryption"); Common::File erf; open(erf); if (!erf.seek(res.offset)) throw Common::Exception(Common::kSeekError); byte *compressedData = new byte[res.packedSize]; if (erf.read(compressedData, res.packedSize) != res.packedSize) { delete[] compressedData; throw Common::Exception(Common::kReadError); } return decompress(compressedData, res.packedSize, res.unpackedSize); }
bool FPSfx::loadVoiceFromVDB(Common::File &vdbFP) { if (!_soundSupported) return true; switch (g_vm->_vdbCodec) { case FPCODEC_ADPCM: { uint32 size = vdbFP.readUint32LE(); uint32 rate = vdbFP.readUint32LE(); _rewindableStream = Audio::makeADPCMStream(vdbFP.readStream(size), DisposeAfterUse::YES, 0, Audio::kADPCMDVI, rate, 1); } break; case FPCODEC_MP3 : { #ifdef USE_MAD uint32 size = vdbFP.readUint32LE(); _rewindableStream = Audio::makeMP3Stream(vdbFP.readStream(size), DisposeAfterUse::YES); #else return false; #endif } break; case FPCODEC_OGG : { #ifdef USE_VORBIS uint32 size = vdbFP.readUint32LE(); _rewindableStream = Audio::makeVorbisStream(vdbFP.readStream(size), DisposeAfterUse::YES); #else return false; #endif } break; case FPCODEC_FLAC : { #ifdef USE_FLAC uint32 size = vdbFP.readUint32LE(); _rewindableStream = Audio::makeFLACStream(vdbFP.readStream(size), DisposeAfterUse::YES); #else return false; #endif } break; default: return false; } _isVoice = true; _fileLoaded = true; setVolume(62); return true; }
VideoHandle VideoManager::createVideoHandle(const Common::String &filename, uint16 x, uint16 y, bool loop, byte volume) { // First, check to see if that video is already playing for (uint32 i = 0; i < _videoStreams.size(); i++) if (_videoStreams[i].filename == filename) return i; // Otherwise, create a new entry VideoEntry entry; entry.clear(); entry.video = new Video::QuickTimeDecoder(); entry.x = x; entry.y = y; entry.filename = filename; entry.loop = loop; entry.enabled = true; Common::File *file = new Common::File(); if (!file->open(filename)) { delete file; return NULL_VID_HANDLE; } entry->loadStream(file); entry->setVolume(volume); entry->start(); // Search for any deleted videos so we can take a formerly used slot for (uint32 i = 0; i < _videoStreams.size(); i++) if (!_videoStreams[i].video) { _videoStreams[i] = entry; return i; } // Otherwise, just add it to the list _videoStreams.push_back(entry); return _videoStreams.size() - 1; }
Common::SeekableReadStream *ResMan::open(uint32 fileRef) { // Get the information about the resource ResInfo resInfo; if (!getResInfo(fileRef, resInfo)) { return NULL; } // Do we know the name of the required GJD? if (resInfo.gjd >= _gjds.size()) { error("Groovie::Resource: Unknown GJD %d", resInfo.gjd); return NULL; } debugC(1, kGroovieDebugResource | kGroovieDebugAll, "Groovie::Resource: Opening resource 0x%04X (%s, %d, %d)", fileRef, _gjds[resInfo.gjd].c_str(), resInfo.offset, resInfo.size); // Does it exist? if (!Common::File::exists(_gjds[resInfo.gjd])) { error("Groovie::Resource: %s not found", _gjds[resInfo.gjd].c_str()); return NULL; } // Open the pack file Common::File *gjdFile = new Common::File(); if (!gjdFile->open(_gjds[resInfo.gjd].c_str())) { delete gjdFile; error("Groovie::Resource: Couldn't open %s", _gjds[resInfo.gjd].c_str()); return NULL; } // Save the used gjd file (except xmi and gamwav) if (resInfo.gjd < 19) { _lastGjd = resInfo.gjd; } // Returning the resource substream return new Common::SeekableSubReadStream(gjdFile, resInfo.offset, resInfo.offset + resInfo.size, DisposeAfterUse::YES); }
void Script::o_getcd() { debugScript(1, true, "GETCD"); // By default set it to no CD available int8 cd = -1; // Try to open one file from each CD Common::File cdfile; if (cdfile.open("b.gjd")) { cdfile.close(); cd = 1; } if (cdfile.open("at.gjd")) { cdfile.close(); if (cd == 1) { // Both CDs are available cd = 0; } else { cd = 2; } } setVariable(0x106, cd); }
// Will try to set amiga palette by using "spal" file. If not found, we return false bool GfxPalette::setAmiga() { Common::File file; if (file.open("spal")) { for (int curColor = 0; curColor < 32; curColor++) { byte byte1 = file.readByte(); byte byte2 = file.readByte(); if (file.eos()) error("Amiga palette file ends prematurely"); _sysPalette.colors[curColor].used = 1; _sysPalette.colors[curColor].r = (byte1 & 0x0F) * 0x11; _sysPalette.colors[curColor].g = ((byte2 & 0xF0) >> 4) * 0x11; _sysPalette.colors[curColor].b = (byte2 & 0x0F) * 0x11; } // Directly set the palette, because setOnScreen() wont do a thing for amiga copySysPaletteToScreen(); return true; } return false; }
void CompressionTool::extractAndEncodeWAV(const char *outName, Common::File &input, AudioFormat compMode) { unsigned int length; char fbuf[2048]; size_t size; input.seek(-4, SEEK_CUR); length = input.readUint32LE(); length += 8; input.seek(-8, SEEK_CUR); /* Copy the WAV data to a temporary file */ Common::File f(outName, "wb"); while (length > 0) { size = input.read_noThrow(fbuf, length > sizeof(fbuf) ? sizeof(fbuf) : length); if (size <= 0) break; length -= (int)size; f.write(fbuf, size); } f.close(); /* Convert the WAV temp file to OGG/MP3 */ encodeAudio(outName, false, -1, tempEncoded, compMode); }
bool MD5Check::advanceCheck(int *pos, int *total) { if (_iterator < 0) { return false; } const MD5Sum &sum = (*_files)[_iterator++]; if (pos) { *pos = _iterator; } if (total) { *total = _files->size(); } if ((uint32)_iterator == _files->size()) { _iterator = -1; } Common::File file; if (file.open(sum.filename)) { Common::String md5 = Common::computeStreamMD5AsString(file); if (!checkMD5(sum, md5.c_str())) { warning("'%s' may be corrupted. MD5: '%s'", sum.filename, md5.c_str()); GUI::displayErrorDialog(Common::String::format("The game data file %s may be corrupted.\nIf you are sure it is " "not please provide the ResidualVM team the following code, along with the file name, the language and a " "description of your game version (i.e. dvd-box or jewelcase):\n%s", sum.filename, md5.c_str()).c_str()); return false; } } else { warning("Could not open %s for checking", sum.filename); GUI::displayErrorDialog(Common::String::format("Could not open the file %s for checking.\nIt may be missing or " "you may not have the rights to open it.\nGo to http://wiki.residualvm.org/index.php/Datafiles to see a list " "of the needed files.", sum.filename).c_str()); return false; } return true; }
/** * Draw background animation * @remarks Originally called 'show_one' */ void Background::draw(int16 destX, int16 destY, byte sprId) { assert(sprId < 40); if (_sprites[sprId]._x > kOnDisk) { if (destX < 0) { destX = _sprites[sprId]._x * 8; destY = _sprites[sprId]._y; } drawSprite(destX, destY, _sprites[sprId]); } else { Common::File f; if (!f.open(_filename)) // Filename was set in loadBackgroundSprites(). return; // We skip because some rooms don't have sprites in the background. f.seek(_offsets[sprId]); SpriteType sprite; sprite._type = (PictureType)(f.readByte()); sprite._x = f.readSint16LE(); sprite._y = f.readSint16LE(); sprite._width = f.readSint16LE(); sprite._height = f.readSint16LE(); sprite._size = f.readSint32LE(); f.skip(2); // Natural and Memorize are used in Load() sprite._picture = _vm->_graphics->loadPictureRaw(f, sprite._width * 8, sprite._height + 1); if (destX < 0) { destX = sprite._x * 8; destY = sprite._y; } drawSprite(destX, destY, sprite); sprite._picture.free(); f.close(); } }
Common::SeekableReadStream *SaveManager::getSlotFile(uint slot) { Common::SeekableReadStream *saveFile = g_system->getSavefileManager()->openForLoading(_engine->generateSaveFileName(slot)); if (saveFile == NULL) { // Try to load standard save file Common::String filename; if (_engine->getGameId() == GID_GRANDINQUISITOR) filename = Common::String::format("inqsav%u.sav", slot); else if (_engine->getGameId() == GID_NEMESIS) filename = Common::String::format("nemsav%u.sav", slot); saveFile = _engine->getSearchManager()->openFile(filename); if (saveFile == NULL) { Common::File *tmpFile = new Common::File; if (!tmpFile->open(filename)) { delete tmpFile; } else { saveFile = tmpFile; } } } return saveFile; }
FileManager::FileManager(XeenEngine *vm) { Common::File f; int sideNum = 0; File::_currentArchive = ANY_ARCHIVE; _isDarkCc = vm->getGameID() == GType_DarkSide; _archives[0] = _archives[1] = _archives[2] = nullptr; if (vm->getGameID() != GType_DarkSide) { _archives[0] = new CCArchive("xeen.cc", "xeen", true); SearchMan.add("xeen", _archives[0]); sideNum = 1; } if (vm->getGameID() == GType_DarkSide || vm->getGameID() == GType_WorldOfXeen) { _archives[sideNum] = new CCArchive("dark.cc", "dark", true); SearchMan.add("dark", _archives[sideNum]); } if (f.exists("intro.cc")) { _archives[2] = new CCArchive("intro.cc", "intro", true); SearchMan.add("intro", _archives[2]); } }
const Graphics::Font *ThemeEngine::loadFont(const Common::String &filename) { const Graphics::Font *font = 0; Common::String cacheFilename = genCacheFilename(filename); Common::File fontFile; if (!cacheFilename.empty()) { if (fontFile.open(cacheFilename)) { font = Graphics::BdfFont::loadFromCache(fontFile); } if (font) return font; if ((font = loadCachedFontFromArchive(cacheFilename))) return font; } // normal open if (fontFile.open(filename)) { font = Graphics::BdfFont::loadFont(fontFile); } if (!font) { font = loadFontFromArchive(filename); } if (font) { if (!cacheFilename.empty()) { if (!Graphics::BdfFont::cacheFontData(*(const Graphics::BdfFont *)font, cacheFilename)) { warning("Couldn't create cache file for font '%s'", filename.c_str()); } } } return font; }
Common::SeekableReadStream *InstallShieldCabinet::createReadStreamForMember(const Common::String &name) const { if (!_map.contains(name)) return 0; const FileEntry &entry = _map[name]; Common::File archiveFile; archiveFile.open(_installShieldFilename); archiveFile.seek(entry.offset); if (!(entry.flags & 0x04)) { // Not compressed return archiveFile.readStream(entry.uncompressedSize); } #ifdef USE_ZLIB byte *src = (byte *)malloc(entry.compressedSize); byte *dst = (byte *)malloc(entry.uncompressedSize); archiveFile.read(src, entry.compressedSize); bool result = Common::inflateZlibHeaderless(dst, entry.uncompressedSize, src, entry.compressedSize); free(src); if (!result) { warning("failed to inflate CAB file '%s'", name.c_str()); free(dst); return 0; } return new Common::MemoryReadStream(dst, entry.uncompressedSize, DisposeAfterUse::YES); #else warning("zlib required to extract compressed CAB file '%s'", name.c_str()); return 0; #endif }
Common::SeekableReadStream *Resources::openFile(const Common::String &fileName) { debugC(1, kDebugResource, "openFile(%s)", fileName.c_str()); // first try to find files outside of .pak // some patched files have not been included in package. if (Common::File::exists(fileName)) { Common::File *file = new Common::File(); bool opened = file->open(fileName); if (!opened) { delete file; return 0; } return file; } else { for (uint32 i = 0; i < _pakFiles.size(); i++) { Common::SeekableReadStream *stream = 0; stream = _pakFiles[i]->createReadStream(fileName); if (stream) return stream; } return 0; } }
bool Console::cmdRawToWav(int argc, const char **argv) { if (argc != 3) { debugPrintf("Use %s <rawFilePath> <wavFileName> to dump a .RAW file to .WAV\n", argv[0]); return true; } Common::File file; if (!_engine->getSearchManager()->openFile(file, argv[1])) { warning("File not found: %s", argv[1]); return true; } Audio::AudioStream *audioStream = makeRawZorkStream(argv[1], _engine); Common::DumpFile output; output.open(argv[2]); output.writeUint32BE(MKTAG('R', 'I', 'F', 'F')); output.writeUint32LE(file.size() * 2 + 36); output.writeUint32BE(MKTAG('W', 'A', 'V', 'E')); output.writeUint32BE(MKTAG('f', 'm', 't', ' ')); output.writeUint32LE(16); output.writeUint16LE(1); uint16 numChannels; if (audioStream->isStereo()) { numChannels = 2; output.writeUint16LE(2); } else { numChannels = 1; output.writeUint16LE(1); } output.writeUint32LE(audioStream->getRate()); output.writeUint32LE(audioStream->getRate() * numChannels * 2); output.writeUint16LE(numChannels * 2); output.writeUint16LE(16); output.writeUint32BE(MKTAG('d', 'a', 't', 'a')); output.writeUint32LE(file.size() * 2); int16 *buffer = new int16[file.size()]; audioStream->readBuffer(buffer, file.size()); #ifndef SCUMM_LITTLE_ENDIAN for (int i = 0; i < file.size(); ++i) buffer[i] = TO_LE_16(buffer[i]); #endif output.write(buffer, file.size() * 2); delete[] buffer; return true; }
void AGOSEngine::loadOffsets(const char *filename, int number, uint32 &file, uint32 &offset, uint32 &srcSize, uint32 &dstSize) { Common::File in; int offsSize = (getPlatform() == Common::kPlatformAmiga) ? 16 : 12; /* read offsets from index */ in.open(filename); if (in.isOpen() == false) { error("loadOffsets: Can't load index file '%s'", filename); } in.seek(number * offsSize, SEEK_SET); offset = in.readUint32LE(); dstSize = in.readUint32LE(); srcSize = in.readUint32LE(); file = in.readUint32LE(); in.close(); }
Common::Error LabEngine::run() { if (getFeatures() & GF_LOWRES) initGraphics(320, 200, false); else initGraphics(640, 480, true); _event = new EventManager(this); _resource = new Resource(this); _music = new Music(this); _graphics = new DisplayMan(this); _anim = new Anim(this); _specialLocks = new SpecialLocks(this); _utils = new Utils(this); _console = new Console(this); _journalBackImage = new Image(this); if (getPlatform() == Common::kPlatformWindows) { // Check if this is the Wyrmkeep trial Common::File roomFile; bool knownVersion = true; bool roomFileOpened = roomFile.open("game/rooms/48"); if (!roomFileOpened) knownVersion = false; else if (roomFile.size() != 892) knownVersion = false; else { roomFile.seek(352); byte checkByte = roomFile.readByte(); if (checkByte == 0x00) { // Full Windows version } else if (checkByte == 0x80) { // Wyrmkeep trial version _extraGameFeatures = GF_WINDOWS_TRIAL; GUI::MessageDialog trialMessage("This is a trial Windows version of the game. To play the full version, you will need to use the original interpreter and purchase a key from Wyrmkeep"); trialMessage.runModal(); } else { knownVersion = false; } roomFile.close(); if (!knownVersion) { warning("Unknown Windows version found, please report this version to the ScummVM team"); return Common::kNoGameDataFoundError; } } } go(); return Common::kNoError; }
bool Resource::readTableFile(const GameVersion *gameVersion) { Common::File tableFile; tableFile.open(_tableFilename); if (tableFile.isOpen() && tableFile.readUint32BE() == 'QTBL') { if (tableFile.readUint32BE() != CURRENT_TBL_VERSION) warning("Incorrect version of queen.tbl, please update it"); tableFile.seek(gameVersion->tableOffset); readTableEntries(&tableFile); return true; } return false; }
/** * Allocates enough RAM to hold the global Glitter variables. */ void RegisterGlobals(int num) { if (pGlobals == NULL) { numGlobals = num; hMasterScript = !TinselV2 ? 0 : READ_LE_UINT32(FindChunk(MASTER_SCNHANDLE, CHUNK_MASTER_SCRIPT)); // Allocate RAM for pGlobals and make sure it's allocated pGlobals = (int32 *)calloc(numGlobals, sizeof(int32)); if (pGlobals == NULL) { error("Cannot allocate memory for global data"); } // Allocate RAM for interpret contexts and make sure it's allocated icList = (INT_CONTEXT *)calloc(NUM_INTERPRET, sizeof(INT_CONTEXT)); if (icList == NULL) { error("Cannot allocate memory for interpret contexts"); } g_scheduler->setResourceCallback(FreeInterpretContextPr); } else { // Check size is still the same assert(numGlobals == num); memset(pGlobals, 0, numGlobals * sizeof(int32)); memset(icList, 0, NUM_INTERPRET * sizeof(INT_CONTEXT)); } if (TinselV2) { // read initial values CdCD(nullContext); Common::File f; if (!f.open(GLOBALS_FILENAME)) error(CANNOT_FIND_FILE, GLOBALS_FILENAME); int32 length = f.readSint32LE(); if (length != num) error(FILE_IS_CORRUPT, GLOBALS_FILENAME); for (int i = 0; i < length; ++i) pGlobals[i] = f.readSint32LE(); if (f.eos() || f.err()) error(FILE_IS_CORRUPT, GLOBALS_FILENAME); f.close(); } }
int main(int argc, char *argv[]) { if (argc < 2) { printf("Format: %s ST.exe [ST_german.exe] [titanic.dat]\n", argv[0]); exit(0); } if (!inputFile.open(argv[1])) { error("Could not open input file"); } resEng.loadFromEXE(argv[1]); if (argc >= 3) { resGer.loadFromEXE(argv[2]); } 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 if (inputFile.size() == GERMAN_10042D_FILESIZE) { printf("German version detected. You must use an English versoin " "for the primary input file\n"); exit(0); } else { printf("Unknown version of ST.exe specified\n"); exit(0); } if (!outputFile.open(argc == 4 ? argv[3] : "titanic.dat", Common::kFileWriteMode)) { printf("Could not open output file\n"); exit(0); } writeHeader(); writeData(); writeFinalEntryHeader(); inputFile.close(); outputFile.close(); return 0; }
void writeSentenceMappings(const char *name, uint offset, int numValues) { inputFile.seek(offset - FILE_DIFF[_version]); outputFile.seek(dataOffset); uint id; while ((id = inputFile.readLong()) != 0) { outputFile.writeLong(id); for (int ctr = 0; ctr < numValues; ++ctr) outputFile.writeLong(inputFile.readLong()); } uint size = outputFile.size() - dataOffset; writeEntryHeader(name, dataOffset, size); dataOffset += size; }
/** * 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 { error("Missing startup file '%s'", getBootFilename()); } } if (ofp.size() < (int32)sizeof(_vm->_boot)) error("Corrupted startup file"); _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.exit_len = 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_bootCyper[i % s_bootCyperLen]; } ofp.close(); if (checksum) error("Corrupted startup file"); }
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; }
void writePhrases(const char *name, const CommonPhrase *phrases) { for (uint idx = 0; phrases->_str; ++idx, ++phrases) { outputFile.seek(dataOffset + idx * 4); outputFile.writeString(phrases->_str); outputFile.writeLong(phrases->_dialogueId); outputFile.writeLong(phrases->_roomNum); outputFile.writeLong(phrases->_val1); } uint size = outputFile.size() - dataOffset; writeEntryHeader("Phrases/Bellbot", dataOffset, size); dataOffset += size; }