/** * Opens a file and loads a sound effect. * * @param fileName Sfx filename * * @returns True is everything is OK, False otherwise */ bool FPSfx::loadFile(const char *fileName) { if (!_soundSupported) return true; SoundCodecs codec = FPCODEC_UNKNOWN; Common::File file; if (file.open(fileName)) codec = FPCODEC_ADPCM; else if (file.open(setExtension(fileName, ".MP3"))) codec = FPCODEC_MP3; else if (file.open(setExtension(fileName, ".OGG"))) codec = FPCODEC_OGG; else if (file.open(setExtension(fileName, ".FLA"))) codec = FPCODEC_FLAC; else { warning("FPSfx::LoadFile(): Cannot open sfx file!"); return false; } Common::SeekableReadStream *buffer; switch (codec) { case FPCODEC_ADPCM: { if (file.readUint32BE() != MKTAG('A', 'D', 'P', 0x10)) { warning("FPSfx::LoadFile(): Invalid ADP header!"); return false; } uint32 rate = file.readUint32LE(); uint32 channels = file.readUint32LE(); buffer = file.readStream(file.size() - file.pos()); _rewindableStream = Audio::makeADPCMStream(buffer, DisposeAfterUse::YES, 0, Audio::kADPCMDVI, rate, channels); } break; case FPCODEC_MP3: #ifdef USE_MAD buffer = file.readStream(file.size()); _rewindableStream = Audio::makeMP3Stream(buffer, DisposeAfterUse::YES); #endif break; case FPCODEC_OGG: #ifdef USE_VORBIS buffer = file.readStream(file.size()); _rewindableStream = Audio::makeVorbisStream(buffer, DisposeAfterUse::YES); #endif break; case FPCODEC_FLAC: buffer = file.readStream(file.size()); #ifdef USE_FLAC _rewindableStream = Audio::makeFLACStream(buffer, DisposeAfterUse::YES); #endif break; default: return false; } _fileLoaded = true; return true; }
void BIFFile::load() { Common::File bif; open(bif); readHeader(bif); if (_id != kBIFID) throw Common::Exception("Not a BIF file"); if ((_version != kVersion1) && (_version != kVersion11)) throw Common::Exception("Unsupported BIF file version %08X", _version); uint32 varResCount = bif.readUint32LE(); uint32 fixResCount = bif.readUint32LE(); if (fixResCount != 0) throw Common::Exception("TODO: Fixed BIF resources"); _iResources.resize(varResCount); uint32 offVarResTable = bif.readUint32LE(); try { readVarResTable(bif, offVarResTable); if (bif.err()) throw Common::Exception(Common::kReadError); } catch (Common::Exception &e) { e.add("Failed reading BIF file"); throw e; } }
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); } }
void writeParrotLobbyLinkUpdaterEntries() { static const int OFFSETS[3] = { 0x5A5B38, 0x5A5320, 0x5A4360 }; static const int COUNTS[5] = { 7, 5, 6, 9, 1 }; static const int SKIP[5] = { 36, 36, 40, 36, 0 }; uint recordOffset = OFFSETS[_version], linkOffset; byte vals[8]; outputFile.seek(dataOffset); for (int groupNum = 0; groupNum < 4; ++groupNum) { for (int entryNum = 0; entryNum < COUNTS[groupNum]; ++entryNum, recordOffset += 36) { inputFile.seek(recordOffset - FILE_DIFF[_version]); linkOffset = inputFile.readUint32LE(); for (int idx = 0; idx < 8; ++idx) vals[idx] = inputFile.readUint32LE(); // Write out the entry inputFile.seek(linkOffset - FILE_DIFF[_version]); outputFile.writeString(inputFile); outputFile.write(vals, 8); } // Skip space between groups recordOffset += SKIP[groupNum]; } uint size = outputFile.size() - dataOffset; writeEntryHeader("DATA/PARROT_LOBBY_LINK_UPDATOR", dataOffset, size); dataOffset += size; }
void NDSFile::load() { Common::File nds; open(nds); if (!isNDS(nds)) throw Common::Exception("Not a support NDS ROM file"); nds.seek(0x40); uint32 fileNameTableOffset = nds.readUint32LE(); uint32 fileNameTableLength = nds.readUint32LE(); uint32 fatOffset = nds.readUint32LE(); //uint32 fatLength = nds.readUint32LE(); try { readNames(nds, fileNameTableOffset, fileNameTableLength); readFAT(nds, fatOffset); if (nds.err()) throw Common::Exception(Common::kReadError); } catch (Common::Exception &e) { e.add("Failed reading NDS file"); throw; } }
bool XARCArchive::open(const Common::String &filename) { Common::File stream; if (!stream.open(filename)) { return false; } _filename = filename; // Unknown: always 1? version? uint32 unknown = stream.readUint32LE(); debugC(kDebugUnknown, "Stark::XARC: \"%s\" has unknown=%d", _filename.c_str(), unknown); if (unknown != 1) { warning("Stark::XARC: \"%s\" has unknown=%d with unknown meaning", _filename.c_str(), unknown); } // Read the number of contained files uint32 numFiles = stream.readUint32LE(); debugC(20, kDebugArchive, "Stark::XARC: \"%s\" contains %d files", _filename.c_str(), numFiles); // Read the offset to the contents of the first file uint32 offset = stream.readUint32LE(); debugC(20, kDebugArchive, "Stark::XARC: \"%s\"'s first file has offset=%d", _filename.c_str(), offset); for (uint32 i = 0; i < numFiles; i++) { XARCMember *member = new XARCMember(this, stream, offset); _members.push_back(Common::ArchiveMemberPtr(member)); // Set the offset to the next member offset += member->getLength(); } return true; }
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 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); } }
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(); } }
Common::SeekableReadStream *Hqr::createReadStreamForIndex(int index) const { if (index >= _numIndices) return 0; uint32 realSize; uint32 compressedSize; uint16 mode; Common::File *file = new Common::File(); file->open(_hqrFileName); file->seek(_indices[index]); realSize = file->readUint32LE(); compressedSize = file->readUint32LE(); mode = file->readUint16LE(); uint32 begin = _indices[index] + 10; uint32 end = 0; if (mode == 0) { end = begin + realSize; } else { end = begin + compressedSize; } Common::SeekableReadStream *stream = new Common::SeekableSubReadStream(file, begin, end, DisposeAfterUse::YES); if (mode != 0) { stream = new LzssReadStream(stream, mode, realSize); } return stream; }
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); } }
bool SliceAnimations::open(const Common::String &name) { Common::File file; if (!file.open(_vm->getResourceStream(name), name)) return false; _timestamp = file.readUint32LE(); _pageSize = file.readUint32LE(); _pageCount = file.readUint32LE(); _paletteCount = file.readUint32LE(); if (_timestamp != 0x3457b6f6) // Timestamp: Wed, 29 Oct 1997 22:21:42 GMT return false; _palettes.resize(_paletteCount); for (uint32 i = 0; i != _paletteCount; ++i) { for (uint32 j = 0; j != 256; ++j) { uint8 color_r = file.readByte(); uint8 color_g = file.readByte(); uint8 color_b = file.readByte(); _palettes[i].color[j].r = color_r; _palettes[i].color[j].g = color_g; _palettes[i].color[j].b = color_b; uint16 rgb555 = ((uint16)color_r << 10) | ((uint16)color_g << 5) | (uint16)color_b; _palettes[i].color555[j] = rgb555; } } uint32 animationCount = file.readUint32LE(); _animations.resize(animationCount); for (uint32 i = 0; i != animationCount; ++i) { _animations[i].frameCount = file.readUint32LE(); _animations[i].frameSize = file.readUint32LE(); _animations[i].fps = file.readFloatLE(); _animations[i].positionChange.x = file.readFloatLE(); _animations[i].positionChange.y = file.readFloatLE(); _animations[i].positionChange.z = file.readFloatLE(); _animations[i].facingChange = file.readFloatLE(); _animations[i].offset = file.readUint32LE(); } _pages.resize(_pageCount); for (uint32 i = 0; i != _pageCount; ++i) _pages[i]._data = nullptr; return true; }
void Music::loadSoundEffect(const Common::String filename, bool loop, bool waitTillFinished) { stopSoundEffect(); Common::File *file = _vm->_resource->openDataFile(filename, MKTAG('D', 'I', 'F', 'F')); if (!file) return; _vm->_anim->_doBlack = false; uint32 magicBytes = file->readUint32LE(); if (magicBytes != 1219009121) { warning("readSound: Bad signature, skipping"); return; } uint32 soundTag = file->readUint32LE(); uint32 soundSize = file->readUint32LE(); if (soundTag != 0) return; file->skip(soundSize); // skip the header while (soundTag != 65535) { _vm->updateEvents(); soundTag = file->readUint32LE(); soundSize = file->readUint32LE() - 8; if ((soundTag == 30) || (soundTag == 31)) { if (waitTillFinished) { while (isSoundEffectActive()) { _vm->updateEvents(); _vm->waitTOF(); } } file->skip(4); uint16 sampleRate = file->readUint16LE(); file->skip(2); playSoundEffect(sampleRate, soundSize, loop, file); } else if (soundTag == 65535) { if (waitTillFinished) { while (isSoundEffectActive()) { _vm->updateEvents(); _vm->waitTOF(); } } } else file->skip(soundSize); } }
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; }
// 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); for (;;) { 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) { const ResourceId resId(kResourceTypeAudio, n); if (unload) removeAudioResource(resId); else addResource(resId, src, offset, size, map->getLocationName()); } else { warning("Failed to find audio volume %i", volume_nr); return SCI_ERROR_NO_RESOURCE_FILES_FOUND; } }
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; }
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(); }
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; }
uint32 CompressTouche::compress_sound_data_file(uint32 current_offset, Common::File &output, Common::File &input, uint32 *offs_table, uint32 *size_table, int len) { int i, size; uint8 buf[2048]; uint32 start_offset = current_offset; /* write 0 offsets/sizes table */ for (i = 0; i < len; ++i) { offs_table[i] = input.readUint32LE(); size_table[i] = input.readUint32LE(); output.writeUint32LE(0); output.writeUint32LE(0); current_offset += 8; } for (i = 0; i < len; ++i) { if (size_table[i] == 0) { offs_table[i] = 0; } else { input.seek(offs_table[i], SEEK_SET); input.read_throwsOnError(buf, 8); if (memcmp(buf, "Creative", 8) != 0) { error("Invalid VOC data found"); } print("VOC found (pos = %d) :", offs_table[i]); input.seek(18, SEEK_CUR); extractAndEncodeVOC(TEMP_RAW, input, _format); /* append converted data to output file */ Common::File temp(tempEncoded, "rb"); size_table[i] = 0; while ((size = temp.read_noThrow(buf, 2048)) > 0) { output.write(buf, size); size_table[i] += size; } offs_table[i] = current_offset; current_offset += size_table[i]; } } /* fix data offsets table */ output.seek(start_offset, SEEK_SET); for (i = 0; i < len; ++i) { output.writeUint32LE(offs_table[i]); output.writeUint32LE(size_table[i]); } output.seek(0, SEEK_END); return current_offset; }
bool MADSResourceManager::resourceExists(const char *resourceName) { Common::File hagFile; uint32 offset, 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) return false; else return true; }
GameList SkyMetaEngine::detectGames(const Common::FSList &fslist) const { GameList detectedGames; bool hasSkyDsk = false; bool hasSkyDnr = false; int dinnerTableEntries = -1; int dataDiskSize = -1; // Iterate over all files in the given directory for (Common::FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) { if (!file->isDirectory()) { const char *fileName = file->getName().c_str(); if (0 == scumm_stricmp("sky.dsk", fileName)) { Common::File dataDisk; if (dataDisk.open(*file)) { hasSkyDsk = true; dataDiskSize = dataDisk.size(); } } if (0 == scumm_stricmp("sky.dnr", fileName)) { Common::File dinner; if (dinner.open(*file)) { hasSkyDnr = true; dinnerTableEntries = dinner.readUint32LE(); } } } } if (hasSkyDsk && hasSkyDnr) { // Match found, add to list of candidates, then abort inner loop. // The game detector uses US English by default. We want British // English to match the recorded voices better. GameDescriptor dg("sky", skySetting.gameid, skySetting.description, Common::UNK_LANG, Common::kPlatformUnknown); const SkyVersion *sv = skyVersions; while (sv->dinnerTableEntries) { if (dinnerTableEntries == sv->dinnerTableEntries && (sv->dataDiskSize == dataDiskSize || sv->dataDiskSize == -1)) { dg.updateDesc(Common::String::format("v0.0%d %s", sv->version, sv->extraDesc).c_str()); dg.setGUIOptions(sv->guioptions); break; } ++sv; } detectedGames.push_back(dg); } return detectedGames; }
BaseSound::BaseSound(Audio::Mixer *mixer, const Common::String &filename, uint32 base, bool bigEndian) : _mixer(mixer), _filename(filename), _offsets(NULL) { uint res = 0; uint32 size; Common::File file; if (!file.open(_filename)) error("BaseSound: Could not open file \"%s\"", filename.c_str()); file.seek(base + sizeof(uint32), SEEK_SET); if (bigEndian) size = file.readUint32BE(); else size = file.readUint32LE(); // The Feeble Files uses set amount of voice offsets if (size == 0) size = 40000; res = size / sizeof(uint32); _offsets = (uint32 *)malloc(size + sizeof(uint32)); _freeOffsets = true; file.seek(base, SEEK_SET); for (uint i = 0; i < res; i++) { if (bigEndian) _offsets[i] = base + file.readUint32BE(); else _offsets[i] = base + file.readUint32LE(); } _offsets[res] = file.size(); }
void GameModule::load(const char *filename) { debug(0, "GameModule::load()"); unload(); Common::File fd; if (!fd.open(filename)) error("GameModule::load() Could not open %s", filename); loadBgSprites(fd); loadCameraInits(fd); loadWalkRects(fd); loadSceneExits(fd); loadBgObjects(fd); loadAnimations(fd); loadSceneObjectDefs(fd); loadSceneObjectInits(fd); loadActions(fd); loadGuiSpriteIndices(fd); loadInventoryItemSpriteIndices(fd); loadInventoryItemInfos(fd); loadDialogItemSpriteIndices(fd); loadSceneSounds(fd); loadPreloadSounds(fd); fd.seek(0xC); _fieldC = fd.readUint32LE(); fd.seek(0x1A8); _buttheadObjectIndex = fd.readUint32LE(); fd.close(); debug(0, "GameModule::load() OK"); }
void ScummEngine_v4::loadCharset(int no) { uint32 size; memset(_charsetData, 0, sizeof(_charsetData)); assertRange(0, no, 4, "charset"); closeRoom(); Common::File file; char buf[20]; sprintf(buf, "%03d.LFL", 900 + no); file.open(buf); if (file.isOpen() == false) { error("loadCharset(%d): Missing file charset: %s", no, buf); } size = file.readUint32LE() + 11; file.read(_res->createResource(rtCharset, no, size), size); }
/** * Read sound (or music) file data. Call with SILENCE to free-up * any allocated memory. Also returns size of data */ SoundPtr FileManager::getSound(const int16 sound, uint16 *size) { debugC(1, kDebugFile, "getSound(%d)", sound); // No more to do if SILENCE (called for cleanup purposes) if (sound == _vm->_soundSilence) return 0; // Open sounds file Common::File fp; // Handle to SOUND_FILE if (!fp.open(getSoundFilename())) { warning("Hugo Error: File not found %s", getSoundFilename()); return 0; } if (!_hasReadHeader) { for (int i = 0; i < kMaxSounds; i++) { _soundHdr[i]._size = fp.readUint16LE(); _soundHdr[i]._offset = fp.readUint32LE(); } if (fp.err()) error("Wrong sound file format"); _hasReadHeader = true; } *size = _soundHdr[sound]._size; if (*size == 0) error("Wrong sound file format or missing sound %d", sound); // Allocate memory for sound or music, if possible SoundPtr soundPtr = (byte *)malloc(_soundHdr[sound]._size); // Ptr to sound data assert(soundPtr); // Seek to data and read it fp.seek(_soundHdr[sound]._offset, SEEK_SET); if (fp.read(soundPtr, _soundHdr[sound]._size) != _soundHdr[sound]._size) error("Wrong sound file format"); fp.close(); return soundPtr; }
void LabEngine::loadMapData() { Common::File *mapImages = _resource->openDataFile("P:MapImage"); _imgMap = new Image(mapImages, this); _imgRoom = new Image(mapImages, this); _imgUpArrowRoom = new Image(mapImages, this); _imgDownArrowRoom = new Image(mapImages, this); _imgHRoom = new Image(mapImages, this); _imgVRoom = new Image(mapImages, this); _imgMaze = new Image(mapImages, this); _imgHugeMaze = new Image(mapImages, this); _imgMapX[kDirectionNorth] = new Image(mapImages, this); _imgMapX[kDirectionEast] = new Image(mapImages, this); _imgMapX[kDirectionSouth] = new Image(mapImages, this); _imgMapX[kDirectionWest] = new Image(mapImages, this); _imgPath = new Image(mapImages, this); _imgBridge = new Image(mapImages, this); _mapButtonList.push_back(_interface->createButton( 8, _utils->vgaScaleY(105), 0, Common::KEYCODE_ESCAPE, new Image(mapImages, this), new Image(mapImages, this))); // back _mapButtonList.push_back(_interface->createButton( 55, _utils->vgaScaleY(105), 1, Common::KEYCODE_UP, new Image(mapImages, this), new Image(mapImages, this))); // up _mapButtonList.push_back(_interface->createButton(101, _utils->vgaScaleY(105), 2, Common::KEYCODE_DOWN, new Image(mapImages, this), new Image(mapImages, this))); // down delete mapImages; Common::File *mapFile = _resource->openDataFile("Lab:Maps", MKTAG('M', 'A', 'P', '0')); updateEvents(); _maxRooms = mapFile->readUint16LE(); _maps = new MapData[_maxRooms + 1]; // will be freed when the user exits the map for (int i = 0; i <= _maxRooms; i++) { _maps[i]._x = mapFile->readUint16LE(); _maps[i]._y = mapFile->readUint16LE(); _maps[i]._pageNumber = mapFile->readUint16LE(); _maps[i]._specialID = (SpecialRoom) mapFile->readUint16LE(); _maps[i]._mapFlags = mapFile->readUint32LE(); } delete mapFile; }
bool ScummDebugger::Cmd_ImportRes(int argc, const char** argv) { Common::File file; uint32 size; int resnum; if (argc != 4) { DebugPrintf("Syntax: importres <restype> <filename> <resnum>\n"); return true; } resnum = atoi(argv[3]); // FIXME add bounds check if (!strncmp(argv[1], "scr", 3)) { file.open(argv[2], Common::File::kFileReadMode); if (file.isOpen() == false) { DebugPrintf("Could not open file %s\n", argv[2]); return true; } if (_vm->_game.features & GF_SMALL_HEADER) { size = file.readUint16LE(); file.seek(-2, SEEK_CUR); } else if (_vm->_game.features & GF_SMALL_HEADER) { if (_vm->_game.version == 4) file.seek(8, SEEK_CUR); size = file.readUint32LE(); file.readUint16LE(); file.seek(-6, SEEK_CUR); } else { file.readUint32BE(); size = file.readUint32BE(); file.seek(-8, SEEK_CUR); } file.read(_vm->res.createResource(rtScript, resnum, size), size); } else DebugPrintf("Unknown importres type '%s'\n", argv[1]); return true; }
/** * Returns address of uif_hdr[id], reading it in if first call * This file contains, between others, the bitmaps of the fonts used in the application * UIF means User interface database (Windows Only) */ UifHdr *FileManager::getUIFHeader(const Uif id) { debugC(1, kDebugFile, "getUIFHeader(%d)", id); // Initialize offset lookup if not read yet if (_firstUIFFl) { _firstUIFFl = false; // Open unbuffered to do far read Common::File ip; // Image data file if (!ip.open(getUifFilename())) error("File not found: %s", getUifFilename()); if (ip.size() < (int32)sizeof(_UIFHeader)) error("Wrong UIF file format"); for (int i = 0; i < kMaxUifs; ++i) { _UIFHeader[i]._size = ip.readUint16LE(); _UIFHeader[i]._offset = ip.readUint32LE(); } ip.close(); } return &_UIFHeader[id]; }
void SpriteModule::load(const char *filename) { unload(); Common::File fd; if (!fd.open(filename)) error("SpriteModule::load() Could not open %s", filename); fd.readUint32LE(); // Skip magic fd.readUint32LE(); // Skip unused fd.readUint32LE(); // Skip filesize _paletteOffs = fd.readUint32LE(); fd.readUint32LE(); // Skip unused flagsTbl1Ofs fd.readUint32LE(); // Skip unused flagsTbl2Ofs _spriteTblOffs = fd.readUint32LE(); _paletteStart = fd.readUint32LE(); _paletteCount = fd.readUint32LE(); _spritesCount = fd.readUint32LE(); debug(0, "_paletteOffs: %08X", _paletteOffs); debug(0, "_spriteTblOffs: %08X", _spriteTblOffs); debug(0, "_paletteStart: %d", _paletteStart); debug(0, "_paletteCount: %d", _paletteCount); debug(0, "_spritesCount: %d", _spritesCount); _spriteDataSize = fd.size(); _spriteData = new byte[_spriteDataSize]; fd.seek(0); fd.read(_spriteData, _spriteDataSize); // Convert palette byte *palette = _spriteData + _paletteOffs; for (int i = 0; i < _paletteCount; ++i) { palette[i * 3 + 0] <<= 2; palette[i * 3 + 1] <<= 2; palette[i * 3 + 2] <<= 2; } }
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); }