void MadsM4Engine::dumpFile(const char* filename, bool uncompress) { Common::DumpFile f; byte buffer[DUMP_BUFFER_SIZE]; Common::SeekableReadStream *fileS = res()->get(filename); if (!f.open(filename)) error("Could not open '%s' for writing", filename); int bytesRead = 0; warning("Dumping %s, size: %i\n", filename, fileS->size()); if (!uncompress) { while (!fileS->eos()) { bytesRead = fileS->read(buffer, DUMP_BUFFER_SIZE); f.write(buffer, bytesRead); } } else { MadsPack packData(fileS); Common::SeekableReadStream *sourceUnc; for (int i = 0; i < packData.getCount(); i++) { sourceUnc = packData.getItemStream(i); debugCN(kDebugCore, "Dumping compressed chunk %i of %i, size is %i\n", i + 1, packData.getCount(), sourceUnc->size()); while (!sourceUnc->eos()) { bytesRead = sourceUnc->read(buffer, DUMP_BUFFER_SIZE); f.write(buffer, bytesRead); } delete sourceUnc; } } f.close(); res()->toss(filename); res()->purge(); }
bool loadObjectScripts(Common::SeekableReadStream &in) { int size = in.readSint16BE(); for (int i = 0; i < size; i++) { loadScriptFromSave(in, false); } return !(in.eos() || in.err()); }
bool loadOverlayList(Common::SeekableReadStream &in) { int size = in.readSint16BE(); for (int i = 0; i < size; i++) { loadOverlayFromSave(in); } return !(in.eos() || in.err()); }
void TwoDAFile::readRows2a(Common::SeekableReadStream &twoda, Common::StreamTokenizer &tokenize) { /* And now read the individual cells in the rows. */ size_t columnCount = _headers.size(); while (!twoda.eos()) { TwoDARow *row = new TwoDARow(*this); // Skip the first token, which is the row index. It's implicit in the data anyway tokenize.skipToken(twoda); // Read all the cells in the row size_t count = tokenize.getTokens(twoda, row->_data, columnCount, columnCount); // And move to the next line tokenize.nextChunk(twoda); if (count == 0) { // Ignore empty lines delete row; continue; } _rows.push_back(row); } }
PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) : Control(engine, key) { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); while (!stream.eos() && !line.contains('}')) { if (line.matchString("*_hotspot*", true)) { uint x; uint y; uint width; uint height; sscanf(line.c_str(), "%*[^(](%u,%u,%u,%u)", &x, &y, &width, &height); _hotspot = Common::Rect(x, y, x + width, y + height); } else if (line.matchString("cursor*", true)) { char nameBuffer[25]; sscanf(line.c_str(), "%*[^(](%25[^)])", nameBuffer); _hoverCursor = Common::String(nameBuffer); } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } if (_hotspot.isEmpty() || _hoverCursor.empty()) { warning("Push_toggle cursor %u was parsed incorrectly", key); } }
LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) : Control(engine, key), _frameInfo(0), _frameCount(0), _startFrame(0), _currentFrame(0), _lastRenderedFrame(0), _mouseIsCaptured(false), _isReturning(false), _accumulatedTime(0), _returnRoutesCurrentFrame(0) { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); while (!stream.eos() && !line.contains('}')) { if (line.matchString("*descfile*", true)) { char levFileName[25]; sscanf(line.c_str(), "%*[^(](%25[^)])", levFileName); parseLevFile(levFileName); } else if (line.matchString("*cursor*", true)) { char cursorName[25]; sscanf(line.c_str(), "%*[^(](%25[^)])", cursorName); _cursorName = Common::String(cursorName); } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } renderFrame(_currentFrame); }
void Surface::load(Common::SeekableReadStream &stream, Type type) { //debug(0, "load()"); free(); x = y = 0; uint16 w_ = stream.readUint16LE(); uint16 h_ = stream.readUint16LE(); if (type != kTypeLan) { uint16 pos = stream.readUint16LE(); x = pos % 320; y = pos / 320; } //debug(0, "declared info: %ux%u (%04xx%04x) -> %u,%u", w_, h_, w_, h_, x, y); if (stream.eos() || w_ == 0) return; if (w_ * h_ > stream.size()) { debug(0, "invalid surface %ux%u -> %u,%u", w_, h_, x, y); return; } //debug(0, "creating surface %ux%u -> %u,%u", w_, h_, x, y); create(w_, h_, Graphics::PixelFormat::createFormatCLUT8()); stream.read(pixels, w_ * h_); }
void Control::parseTiltControl(ZVision *engine, Common::SeekableReadStream &stream) { RenderTable *renderTable = engine->getRenderManager()->getRenderTable(); renderTable->setRenderState(RenderTable::TILT); // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); while (!stream.eos() && !line.contains('}')) { if (line.matchString("angle*", true)) { float fov; sscanf(line.c_str(), "angle(%f)", &fov); renderTable->setTiltFoV(fov); } else if (line.matchString("linscale*", true)) { float scale; sscanf(line.c_str(), "linscale(%f)", &scale); renderTable->setTiltScale(scale); } else if (line.matchString("reversepana*", true)) { uint reverse; sscanf(line.c_str(), "reversepana(%u)", &reverse); if (reverse == 1) { renderTable->setTiltReverse(true); } } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } renderTable->generateRenderTable(); }
bool CUP_Player::parseNextHeaderTag(Common::SeekableReadStream &dataStream) { uint32 tag = dataStream.readUint32BE(); uint32 size = dataStream.readUint32BE() - 8; if (dataStream.eos()) return false; uint32 next = dataStream.pos() + size; debug(1, "New header tag %s %d dataSize %d", tag2str(tag), size, _dataSize); switch (tag) { case MKTAG('H','E','A','D'): handleHEAD(dataStream, size); break; case MKTAG('S','F','X','B'): handleSFXB(dataStream, size); break; case MKTAG('R','G','B','S'): handleRGBS(dataStream, size); break; case MKTAG('D','A','T','A'): _dataSize = size; return false; case MKTAG('G','F','X','B'): // this is never triggered default: warning("Unhandled tag %s", tag2str(tag)); break; } dataStream.seek(next); return true; }
bool BITDDecoder::loadStream(Common::SeekableReadStream &stream) { int x = 0, y = 0; // If the stream has exactly the required number of bits for this image, // we assume it is uncompressed. if (stream.size() * 8 == _surface->pitch * _surface->h) { debugC(3, kDebugImages, "Skipping compression"); for (y = 0; y < _surface->h; y++) { for (x = 0; x < _surface->pitch; ) { byte color = stream.readByte(); for (int c = 0; c < 8; c++) *((byte *)_surface->getBasePtr(x++, y)) = (color & (1 << (7 - c))) ? 0 : 0xff; } } return true; } while (y < _surface->h) { int n = stream.readSByte(); int count; int b = 0; int state = 0; if (stream.eos()) break; if ((n >= 0) && (n <= 127)) { // If n is between 0 and 127 inclusive, copy the next n+1 bytes literally. count = n + 1; state = 1; } else if ((n >= -127) && (n <= -1)) { // Else if n is between -127 and -1 inclusive, copy the next byte -n+1 times. b = stream.readByte(); count = -n + 1; state = 2; } else { // Else if n is -128, noop. count = 0; } for (int i = 0; i < count && y < _surface->h; i++) { byte color = 0; if (state == 1) { color = stream.readByte(); } else if (state == 2) color = b; for (int c = 0; c < 8; c++) { *((byte *)_surface->getBasePtr(x, y)) = (color & (1 << (7 - c))) ? 0 : 0xff; x++; if (x == _surface->pitch) { y++; x = 0; break; } } } } return true; }
bool ResLoaderPak::isLoadable(const Common::String &filename, Common::SeekableReadStream &stream) const { int32 filesize = stream.size(); if (filesize < 0) return false; int32 offset = 0; bool switchEndian = false; bool firstFile = true; offset = stream.readUint32LE(); if (offset > filesize || offset < 0) { switchEndian = true; offset = SWAP_BYTES_32(offset); } int32 firstOffset = offset; Common::String file; while (!stream.eos()) { // The start offset of a file should never be in the filelist if (offset < stream.pos() || offset > filesize || offset < 0) return false; file = readString(stream); if (stream.eos()) return false; // Quit now if we encounter an empty string if (file.empty()) { if (firstFile) return false; else break; } firstFile = false; offset = switchEndian ? stream.readUint32BE() : stream.readUint32LE(); if (!offset || offset == filesize || firstOffset == stream.pos()) break; } return true; }
void TwoDAFile::readHeaders2a(Common::SeekableReadStream &twoda, Common::StreamTokenizer &tokenize) { /* Read the column headers of an ASCII 2DA file. */ while (!twoda.eos() && (tokenize.getTokens(twoda, _headers) == 0)) tokenize.nextChunk(twoda); tokenize.nextChunk(twoda); }
bool loadScreenParams(Common::SeekableReadStream &in) { // TODO: handle screen params (really required ?) in.readUint16BE(); in.readUint16BE(); in.readUint16BE(); in.readUint16BE(); in.readUint16BE(); in.readUint16BE(); return !(in.eos() || in.err()); }
bool IFFDecoder::loadStream(Common::SeekableReadStream &stream) { destroy(); const uint32 form = stream.readUint32BE(); if (form != ID_FORM) { warning("Failed reading IFF-file"); return false; } stream.skip(4); const uint32 type = stream.readUint32BE(); switch (type) { case ID_ILBM: _type = TYPE_ILBM; break; case ID_PBM: _type = TYPE_PBM; break; } if (type == TYPE_UNKNOWN) { warning("Failed reading IFF-file"); return false; } while (1) { const uint32 chunkType = stream.readUint32BE(); const uint32 chunkSize = stream.readUint32BE(); if (stream.eos()) break; switch (chunkType) { case ID_BMHD: loadHeader(stream); break; case ID_CMAP: loadPalette(stream, chunkSize); break; case ID_CRNG: loadPaletteRange(stream, chunkSize); break; case ID_BODY: loadBitmap(stream); break; default: stream.skip(chunkSize); } } return true; }
InputControl::InputControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) : Control(engine, key), _nextTabstop(0), _focused(false), _textChanged(false), _cursorOffset(0) { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); while (!stream.eos() && !line.contains('}')) { if (line.matchString("*rectangle*", true)) { int x1; int y1; int x2; int y2; sscanf(line.c_str(), "%*[^(](%d %d %d %d)", &x1, &y1, &x2, &y2); _textRectangle = Common::Rect(x1, y1, x2, y2); } else if (line.matchString("*aux_hotspot*", true)) { int x1; int y1; int x2; int y2; sscanf(line.c_str(), "%*[^(](%d %d %d %d)", &x1, &y1, &x2, &y2); _headerRectangle = Common::Rect(x1, y1, x2, y2); } else if (line.matchString("*string_init*", true)) { uint fontFormatNumber; sscanf(line.c_str(), "%*[^(](%u)", &fontFormatNumber); _textStyle = _engine->getStringManager()->getTextStyle(fontFormatNumber); } else if (line.matchString("*next_tabstop*", true)) { sscanf(line.c_str(), "%*[^(](%u)", &_nextTabstop); } else if (line.matchString("*cursor_animation*", true)) { char fileName[26]; sscanf(line.c_str(), "%*[^(](%25s %*u)", fileName); _cursorAnimationFileName = Common::String(fileName); } else if (line.matchString("*cursor_dimensions*", true)) { // Ignore, use the dimensions in the animation file } else if (line.matchString("*cursor_animation_frames*", true)) { // Ignore, use the frame count in the animation file } else if (line.matchString("*focus*", true)) { _focused = true; } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } }
bool ScriptManager::parseCriteria(Common::SeekableReadStream &stream, Common::List<Common::List<Puzzle::CriteriaEntry> > &criteriaList) const { // Loop until we find the closing brace Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); // Criteria can be empty if (line.contains('}')) { return false; } // Create a new List to hold the CriteriaEntries criteriaList.push_back(Common::List<Puzzle::CriteriaEntry>()); while (!stream.eos() && !line.contains('}')) { Puzzle::CriteriaEntry entry; // Split the string into tokens using ' ' as a delimiter Common::StringTokenizer tokenizer(line); Common::String token; // Parse the id out of the first token token = tokenizer.nextToken(); sscanf(token.c_str(), "[%u]", &(entry.key)); // Parse the operator out of the second token token = tokenizer.nextToken(); if (token.c_str()[0] == '=') entry.criteriaOperator = Puzzle::EQUAL_TO; else if (token.c_str()[0] == '!') entry.criteriaOperator = Puzzle::NOT_EQUAL_TO; else if (token.c_str()[0] == '>') entry.criteriaOperator = Puzzle::GREATER_THAN; else if (token.c_str()[0] == '<') entry.criteriaOperator = Puzzle::LESS_THAN; // First determine if the last token is an id or a value // Then parse it into 'argument' token = tokenizer.nextToken(); if (token.contains('[')) { sscanf(token.c_str(), "[%u]", &(entry.argument)); entry.argumentIsAKey = true; } else { sscanf(token.c_str(), "%u", &(entry.argument)); entry.argumentIsAKey = false; } criteriaList.back().push_back(entry); line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } return true; }
PushToggleControl::PushToggleControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) : Control(engine, key, CONTROL_PUSHTGL), _countTo(2), _cursor(CursorIndex_Active), _event(Common::EVENT_LBUTTONUP) { _hotspots.clear(); // Loop until we find the closing brace Common::String line = stream.readLine(); _engine->getScriptManager()->trimCommentsAndWhiteSpace(&line); Common::String param; Common::String values; getParams(line, param, values); while (!stream.eos() && !line.contains('}')) { if (param.matchString("*_hotspot", true)) { uint x; uint y; uint width; uint height; sscanf(values.c_str(), "%u,%u,%u,%u", &x, &y, &width, &height); _hotspots.push_back(Common::Rect(x, y, x + width + 1, y + height + 1)); } else if (param.matchString("cursor", true)) { _cursor = _engine->getCursorManager()->getCursorId(values); } else if (param.matchString("animation", true)) { // Not used } else if (param.matchString("sound", true)) { // Not used } else if (param.matchString("count_to", true)) { sscanf(values.c_str(), "%u", &_countTo); } else if (param.matchString("mouse_event", true)) { if (values.equalsIgnoreCase("up")) { _event = Common::EVENT_LBUTTONUP; } else if (values.equalsIgnoreCase("down")) { _event = Common::EVENT_LBUTTONDOWN; } else if (values.equalsIgnoreCase("double")) { // Not used } } else if (param.matchString("venus_id", true)) { _venusId = atoi(values.c_str()); } line = stream.readLine(); _engine->getScriptManager()->trimCommentsAndWhiteSpace(&line); getParams(line, param, values); } if (_hotspots.size() == 0) { warning("Push_toggle %u was parsed incorrectly", key); } }
bool MidiTests::loadMusicInMemory(Common::WriteStream *ws) { Common::SeekableReadStream *midiFile = SearchMan.createReadStreamForMember("music.mid"); if (!midiFile) { Testsuite::logPrintf("Error! Can't open Midi music file, check game data directory for file music.mid\n"); return false; } while (!midiFile->eos()) { byte data = midiFile->readByte(); ws->writeByte(data); } return true; }
SaveControl::SaveControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) : Control(engine, key, CONTROL_SAVE), _saveControl(false) { // Loop until we find the closing brace Common::String line = stream.readLine(); _engine->getScriptManager()->trimCommentsAndWhiteSpace(&line); Common::String param; Common::String values; getParams(line, param, values); while (!stream.eos() && !line.contains('}')) { if (param.matchString("savebox", true)) { int saveId; int inputId; sscanf(values.c_str(), "%d %d", &saveId, &inputId); saveElement elmnt; elmnt.inputKey = inputId; elmnt.saveId = saveId; elmnt.exist = false; _inputs.push_back(elmnt); } else if (param.matchString("control_type", true)) { if (values.contains("save")) _saveControl = true; else _saveControl = false; } line = stream.readLine(); _engine->getScriptManager()->trimCommentsAndWhiteSpace(&line); getParams(line, param, values); } for (saveElmntList::iterator iter = _inputs.begin(); iter != _inputs.end(); ++iter) { Control *ctrl = _engine->getScriptManager()->getControl(iter->inputKey); if (ctrl && ctrl->getType() == Control::CONTROL_INPUT) { InputControl *inp = (InputControl *)ctrl; inp->setReadOnly(!_saveControl); Common::SeekableReadStream *save = _engine->getSaveManager()->getSlotFile(iter->saveId); if (save) { SaveGameHeader header; if (_engine->getSaveManager()->readSaveGameHeader(save, header)) { inp->setText(header.saveName); iter->exist = true; } delete save; } } } }
bool loadObjectTable(Common::SeekableReadStream &in) { in.readUint16BE(); // Entry count in.readUint16BE(); // Entry size for (int i = 0; i < NUM_MAX_OBJECT; i++) { g_cine->_objectTable[i].x = in.readSint16BE(); g_cine->_objectTable[i].y = in.readSint16BE(); g_cine->_objectTable[i].mask = in.readUint16BE(); g_cine->_objectTable[i].frame = in.readSint16BE(); g_cine->_objectTable[i].costume = in.readSint16BE(); in.read(g_cine->_objectTable[i].name, 20); g_cine->_objectTable[i].part = in.readUint16BE(); } return !(in.eos() || in.err()); }
uint16 ResMan_t7g::getRef(Common::String name, Common::String scriptname) { // Get the name of the RL file Common::String rlFileName(t7g_gjds[_lastGjd]); rlFileName += ".rl"; Common::SeekableReadStream *rlFile = 0; if (_macResFork) { // Open the RL file from the resource fork rlFile = _macResFork->getResource(rlFileName); } else { // Open the RL file rlFile = SearchMan.createReadStreamForMember(rlFileName); } if (!rlFile) error("Groovie::Resource: Couldn't open %s", rlFileName.c_str()); uint16 resNum; bool found = false; for (resNum = 0; !found && !rlFile->err() && !rlFile->eos(); resNum++) { // Read the resource name char readname[12]; rlFile->read(readname, 12); // Test whether it's the resource we're searching Common::String resname(readname, 12); if (resname.hasPrefix(name.c_str())) { debugC(2, kGroovieDebugResource | kGroovieDebugAll, "Groovie::Resource: Resource %12s matches %s", readname, name.c_str()); found = true; } // Skip the rest of resource information rlFile->read(readname, 8); } // Close the RL file delete rlFile; // Verify we really found the resource if (!found) { error("Groovie::Resource: Couldn't find resource %s in %s", name.c_str(), rlFileName.c_str()); return (uint16)-1; } return (_lastGjd << 10) | (resNum - 1); }
void ScriptManager::parsePuzzle(Puzzle *puzzle, Common::SeekableReadStream &stream) { Common::String line = stream.readLine(); trimCommentsAndWhiteSpace(&line); while (!stream.eos() && !line.contains('}')) { if (line.matchString("criteria {", true)) { parseCriteria(stream, puzzle->criteriaList); } else if (line.matchString("results {", true)) { parseResults(stream, puzzle->resultActions); } else if (line.matchString("flags {", true)) { setStateFlags(puzzle->key, parseFlags(stream)); } line = stream.readLine(); trimCommentsAndWhiteSpace(&line); } }
void ASFStream::load() { ASFGUID guid = ASFGUID(*_stream); if (guid != s_asfHeader) throw Common::Exception("ASFStream: Missing asf header"); _stream->readUint64LE(); _stream->readUint32LE(); _stream->readByte(); _stream->readByte(); for (;;) { size_t startPos = _stream->pos(); guid = ASFGUID(*_stream); uint64 size = _stream->readUint64LE(); if (_stream->eos()) throw Common::Exception("ASFStream: Unexpected eos"); // TODO: Parse each chunk if (guid == s_asfFileHeader) { parseFileHeader(); } else if (guid == s_asfHead1) { // Should be safe to ignore } else if (guid == s_asfComment) { // Ignored } else if (guid == s_asfStreamHeader) { parseStreamHeader(); } else if (guid == s_asfCodecComment) { // TODO } else if (guid == s_asfDataHeader) { // Done parsing the header break; } else if (guid == s_asfExtendedHeader) { // TODO } else if (guid == s_asfStreamBitRate) { // Ignored } else warning("Found unknown ASF GUID: %s", guid.toString().c_str()); _stream->seek(startPos + size); } // Skip to the beginning of the packets _stream->skip(26); _rewindPos = _stream->pos(); }
LeverControl::LeverControl(ZVision *engine, uint32 key, Common::SeekableReadStream &stream) : Control(engine, key, CONTROL_LEVER), _frameInfo(0), _frameCount(0), _startFrame(0), _currentFrame(0), _lastRenderedFrame(0), _mouseIsCaptured(false), _isReturning(false), _accumulatedTime(0), _returnRoutesCurrentFrame(0), _animation(NULL), _cursor(CursorIndex_Active), _mirrored(false) { // Loop until we find the closing brace Common::String line = stream.readLine(); _engine->getScriptManager()->trimCommentsAndWhiteSpace(&line); Common::String param; Common::String values; getParams(line, param, values); while (!stream.eos() && !line.contains('}')) { if (param.matchString("descfile", true)) { char levFileName[25]; sscanf(values.c_str(), "%24s", levFileName); parseLevFile(levFileName); } else if (param.matchString("cursor", true)) { char cursorName[25]; sscanf(values.c_str(), "%24s", cursorName); _cursor = _engine->getCursorManager()->getCursorId(Common::String(cursorName)); } line = stream.readLine(); _engine->getScriptManager()->trimCommentsAndWhiteSpace(&line); getParams(line, param, values); } renderFrame(_currentFrame); }
bool Infogrames::Instruments::load(Common::SeekableReadStream &ins) { int i; int32 fsize; int32 offset[32]; int32 offsetRepeat[32]; int32 dataOffset; unload(); fsize = ins.readUint32BE(); dataOffset = fsize; for (i = 0; (i < 32) && !ins.eos(); i++) { offset[i] = ins.readUint32BE(); offsetRepeat[i] = ins.readUint32BE(); if ((offset[i] > fsize) || (offsetRepeat[i] > fsize) || (offset[i] < (ins.pos() + 4)) || (offsetRepeat[i] < (ins.pos() + 4))) { // Definitely no real entry anymore ins.seek(-8, SEEK_CUR); break; } dataOffset = MIN(dataOffset, MIN(offset[i], offsetRepeat[i])); ins.skip(4); // Unknown _samples[i].length = ins.readUint16BE() * 2; _samples[i].lengthRepeat = ins.readUint16BE() * 2; } if (dataOffset >= fsize) return false; _count = i; _sampleData = new int8[fsize - dataOffset]; ins.seek(dataOffset + 4); ins.read(_sampleData, fsize - dataOffset); for (i--; i >= 0; i--) { _samples[i].data = _sampleData + (offset[i] - dataOffset); _samples[i].dataRepeat = _sampleData + (offsetRepeat[i] - dataOffset); } return true; }
bool parseInstruction(Common::SeekableReadStream &ncs, Instruction &instr) { instr.address = ncs.pos(); try { instr.opcode = (Opcode) ncs.readByte(); instr.type = (InstructionType) ncs.readByte(); } catch (...) { if (ncs.eos()) return false; throw; } if (((size_t)instr.opcode >= ARRAYSIZE(kParseFunc)) || !kParseFunc[(size_t)instr.opcode]) throw Common::Exception("Invalid opcode 0x%02X", (uint8)instr.opcode); const ParseFunc func = kParseFunc[(size_t)instr.opcode]; (*func)(instr, ncs); return true; }
bool WagProperty::read(Common::SeekableReadStream &stream) { // First read the property's header _propCode = (enum WagPropertyCode) stream.readByte(); _propType = (enum WagPropertyType) stream.readByte(); _propNum = stream.readByte(); _propSize = stream.readUint16LE(); if (stream.eos() || stream.err()) { // Check that we got the whole header _readOk = false; return _readOk; } // Then read the property's data deleteData(); // Delete old data (If any) _propData = new char[_propSize + 1UL]; // Allocate space for property's data plus trailing zero uint32 readBytes = stream.read(_propData, _propSize); // Read the data in _propData[_propSize] = 0; // Set the trailing zero for easy C-style string access _readOk = (_propData != NULL && readBytes == _propSize); // Check that we got the whole data return _readOk; }
SourceListing *BasicSourceListingProvider::getListing(const Common::String &filename, ErrorCode &_err) { _err = OK; if (!_fsDirectory) { _err = SOURCE_PATH_NOT_SET; return nullptr; }; Common::String unixFilename; for (uint i = 0; i < filename.size(); i++) { if (filename[i] == '\\') { unixFilename.insertChar('/', unixFilename.size()); } else { unixFilename.insertChar(filename[i], unixFilename.size()); } } Common::SeekableReadStream *file = _fsDirectory->createReadStreamForMember(unixFilename); Common::Array<Common::String> strings; if (!file) { _err = NO_SUCH_SOURCE; } else { if (file->err()) { _err = UNKNOWN_ERROR; } while (!file->eos()) { strings.push_back(file->readLine()); if (file->err()) { _err = UNKNOWN_ERROR; } } } if (_err == OK) { return new SourceListing(strings); } else { return nullptr; } }
bool loadSeqList(Common::SeekableReadStream &in) { uint size = in.readUint16BE(); SeqListElement tmp; for (uint i = 0; i < size; i++) { tmp.var4 = in.readSint16BE(); tmp.objIdx = in.readUint16BE(); tmp.var8 = in.readSint16BE(); tmp.frame = in.readSint16BE(); tmp.varC = in.readSint16BE(); tmp.varE = in.readSint16BE(); tmp.var10 = in.readSint16BE(); tmp.var12 = in.readSint16BE(); tmp.var14 = in.readSint16BE(); tmp.var16 = in.readSint16BE(); tmp.var18 = in.readSint16BE(); tmp.var1A = in.readSint16BE(); tmp.var1C = in.readSint16BE(); tmp.var1E = in.readSint16BE(); g_cine->_seqList.push_back(tmp); } return !(in.eos() || in.err()); }
void MadsGlobals::loadQuotes() { Common::SeekableReadStream *quoteS = _vm->res()->get("quotes.dat"); int curPos = 0; char buffer[128]; strcpy(buffer, ""); while (true) { uint8 b = quoteS->readByte(); if (quoteS->eos()) break; buffer[curPos++] = b; if (buffer[curPos - 1] == '\0') { // end of string, add it to the strings list _madsQuotes.push_back(strdup(buffer)); curPos = 0; strcpy(buffer, ""); } } _vm->res()->toss("quotes.dat"); }