void GameModule::loadAnimations(Common::SeekableReadStream &s) { debug(0, "GameModule::loadAnimations()"); s.seek(0x168); _animationsCount = s.readUint32LE(); uint32 offs = s.readUint32LE(); _animations = new Animation[_animationsCount]; for (int i = 0; i < _animationsCount; ++i) { Animation &anim = _animations[i]; s.seek(offs + i * 20); anim.frameCount = s.readUint32LE(); uint32 frameSpriteIndicesOffs = s.readUint32LE(); uint32 frameTicksOffs = s.readUint32LE(); uint32 frameRects1Offs = s.readUint32LE(); uint32 frameRects2Offs = s.readUint32LE(); anim.frameSpriteIndices = new int[anim.frameCount]; s.seek(frameSpriteIndicesOffs); for (int j = 0; j < anim.frameCount; ++j) anim.frameSpriteIndices[j] = s.readUint32LE(); anim.frameTicks = new int16[anim.frameCount]; s.seek(frameTicksOffs); for (int j = 0; j < anim.frameCount; ++j) anim.frameTicks[j] = s.readUint16LE(); anim.frameRects1 = new Common::Rect[anim.frameCount]; s.seek(frameRects1Offs); for (int j = 0; j < anim.frameCount; ++j) anim.frameRects1[j] = readRect(s); anim.frameRects2 = new Common::Rect[anim.frameCount]; s.seek(frameRects2Offs); for (int j = 0; j < anim.frameCount; ++j) anim.frameRects2[j] = readRect(s); } }
bool NSParser::NSParser::readRectOrVar(Symbol *symbol, NSParser::VariableList &variables, QRectF& r) { bool result = false; if (symbol->type == NON_TERMINAL) { result = true; if (symbol->symbolIndex == SYM_RECT2) r = readRect(symbol, variables); else if (symbol->symbolIndex == SYM_FIXED_RECT) r = readFixedRect(symbol, variables); else if (symbol->symbolIndex == SYM_VAR) result = readRectVar(symbol, variables, r); else //SYM_RECT_OR_VAR { NonTerminal* nt = static_cast<NonTerminal*>(symbol); switch(nt->ruleIndex) { case PROD_RECT_OR_VAR: r = readRect(searchChild(symbol, SYM_RECT2), variables); break; case PROD_RECT_OR_VAR2: result = readRectVar(symbol, variables, r); break; default: result = false; break; } } } return result; }
void printMorphShape(FILE *f, int length) { int offset, start = fileOffset, here; struct Rect r; struct Shape shape1, shape2; int id = readUInt16(f); printf("\n\t### Morph %i ###\n", id); printf("\t$s%i = new SWF::Morph();\n", id); readRect(f, &r); /* bounds 1 */ readRect(f, &r); /* bounds 2 */ offset = readUInt32(f); here = fileOffset+1; memset(&shape1, 0, sizeof(struct Shape)); memset(&shape2, 0, sizeof(struct Shape)); shape1.shapeType = shape2.shapeType = DEFINESHAPE3; readFillStyleArray(f, &shape1, 1); readLineStyleArray(f, &shape1, 1); byteAlign(); shape1.fillBits = shape2.fillBits = readBits(f,4); shape1.lineBits = shape2.lineBits = readBits(f,4); while(fileOffset < here+offset && readShapeRec(f, &shape1)) ; printf("\n\t$s%i_1 = $s%i->getShape1();\n", id, id); printDefineShape(&shape1, id, 0); byteAlign(); readUInt8(f); /* redundant fill/line bits */ while(fileOffset < start+length && readShapeRec(f, &shape2)) ; printf("\n\t$s%i_2 = $s%i->getShape2();\n", id, id); printDefineShape(&shape1, id, 1); }
void printShape(FILE *f, int length, int shapeType) { struct Shape shape; int id, start = fileOffset; memset(&shape, 0, sizeof(struct Shape)); id = readUInt16(f); shape.shapeType = shapeType; readRect(f, &(shape.bounds)); /* bounds */ readFillStyleArray(f, &shape, 0); readLineStyleArray(f, &shape, 0); byteAlign(); shape.fillBits = readBits(f,4); shape.lineBits = readBits(f,4); while(fileOffset < length+start && readShapeRec(f, &shape)) ; /* go for end tag.. if(fileOffset == length+start && bufbits > 5) printShapeRec(f, &lineBits, &fillBits, 2); */ printf("\n\t### Shape %i ###\n", id); printf("\t$s%i = new SWF::Shape();\n", id); printDefineShape(&shape, id, 0); }
Scene::Scene(Common::String name, Common::SeekableReadStream *data) { debug(9, "Creating scene: %s", name.c_str()); _name = name; _classType = SCENE; _design = new Design(data); _resourceId = 0; _script = NULL; _textBounds = NULL; _fontSize = 0; _fontType = 0; setDesignBounds(readRect(data)); _worldY = data->readSint16BE(); _worldX = data->readSint16BE(); _blocked[NORTH] = (data->readByte() != 0); _blocked[SOUTH] = (data->readByte() != 0); _blocked[EAST] = (data->readByte() != 0); _blocked[WEST] = (data->readByte() != 0); _soundFrequency = data->readSint16BE(); _soundType = data->readByte(); data->readByte(); // unknown _messages[NORTH] = readPascalString(data); _messages[SOUTH] = readPascalString(data); _messages[EAST] = readPascalString(data); _messages[WEST] = readPascalString(data); _soundName = readPascalString(data); _visited = false; delete data; }
void DefineEditTextTag::read(SWFStream& in, movie_definition& m) { _rect = readRect(in); in.align(); in.ensureBytes(2); int flags = in.read_u8(); _hasText = flags & (1 << 7); _wordWrap = flags & (1 << 6); _multiline = flags & (1 << 5); _password = flags & (1 << 4); _readOnly = flags & (1 << 3); const bool hasColor = flags & (1 << 2); const bool hasMaxChars = flags & (1 << 1); const bool hasFont = flags & (1 << 0); flags = in.read_u8(); // 0: no font class, 1 font class and height, can't be true if has_font was true bool hasFontClass = flags & (1 << 7); if (hasFontClass && hasFont ) { IF_VERBOSE_MALFORMED_SWF( log_swferror("DefineEditText: hasFontClass can't be true if " "hasFont is true, ignoring"); );
void GameModule::loadWalkRects(Common::SeekableReadStream &s) { debug(0, "GameModule::loadWalkRects()"); s.seek(0x150); _walkRectsCount = s.readUint32LE(); uint32 offs = s.readUint32LE(); _walkRects = new Common::Rect[_walkRectsCount]; s.seek(offs); for (int i = 0; i < _walkRectsCount; ++i) _walkRects[i] = readRect(s); }
void DesktopServerProto::readRegion(Region *region, BlockingGate *gate) { region->clear(); unsigned int rectCount = gate->readUInt32(); for (unsigned int i = 0; i < rectCount; i++) { Rect r = readRect(gate); if (r.isValid()) { region->addRect(&r); } } }
Obj::Obj(Common::String name, Common::SeekableReadStream *data, int resourceId) { _resourceId = resourceId; _name = name; _classType = OBJ; _currentOwner = NULL; _currentScene = NULL; _index = 0; _design = new Design(data); setDesignBounds(readRect(data)); int16 namePlural = data->readSint16BE(); if (namePlural == 256) _namePlural = true; // TODO: other flags? else if (namePlural == 0) _namePlural = false; else error("Obj <%s> had weird namePlural set (%d)", name.c_str(), namePlural); if (data->readSint16BE() != 0) error("Obj <%s> had short set", name.c_str()); if (data->readByte() != 0) error("Obj <%s> had byte set", name.c_str()); _accuracy = data->readByte(); _value = data->readByte(); _type = data->readSByte(); _damage = data->readByte(); _attackType = data->readSByte(); _numberOfUses = data->readSint16BE(); int16 returnTo = data->readSint16BE(); if (returnTo == 256) // TODO any other possibilities? _returnToRandomScene = true; else if (returnTo == 0) _returnToRandomScene = false; else error("Obj <%s> had weird returnTo set", name.c_str()); _sceneOrOwner = readPascalString(data); _clickMessage = readPascalString(data); _operativeVerb = readPascalString(data); _failureMessage = readPascalString(data); _useMessage = readPascalString(data); _sound = readPascalString(data); delete data; }
void GameModule::loadBgObjects(Common::SeekableReadStream &s) { debug(0, "GameModule::loadBgObjects()"); s.seek(0x160); _bgObjectsCount = s.readUint32LE(); uint32 offs = s.readUint32LE(); _bgObjects = new BgObject[_bgObjectsCount]; s.seek(offs); for (int i = 0; i < _bgObjectsCount; ++i) { s.read(_bgObjects[i].name, 20); _bgObjects[i].rect = readRect(s); } }
void GameModule::loadSceneExits(Common::SeekableReadStream &s) { debug(0, "GameModule::loadSceneExits()"); s.seek(0x158); _sceneExitsCount = s.readUint32LE(); uint32 offs = s.readUint32LE(); _sceneExits = new SceneExit[_sceneExitsCount]; s.seek(offs); for (int i = 0; i < _sceneExitsCount; ++i) { _sceneExits[i].rect = readRect(s); _sceneExits[i].newModuleNum = s.readUint32LE(); } }
void GameModule::loadCameraInits(Common::SeekableReadStream &s) { debug(0, "GameModule::loadCameraInits()"); s.seek(0x20); for (int i = 0; i < kCameraInitsCount; ++i) { CameraInit &cameraInit = _cameraInits[i]; cameraInit.cameraPos = readPoint(s); for (int j = 0; j < 8; ++j) cameraInit.cameraLinks[j] = s.readByte(); for (int j = 0; j < 8; ++j) cameraInit.rects[j] = readRect(s); } }
void ColladaSurface::read(void) { OSG_COLLADA_LOG(("ColladaSurface::read\n")); domFx_surface_commonRef surface = getDOMElementAs<domFx_surface_common>(); switch(surface->getType()) { case FX_SURFACE_TYPE_ENUM_UNTYPED: readUntyped(surface); break; case FX_SURFACE_TYPE_ENUM_1D: read1D(surface); break; case FX_SURFACE_TYPE_ENUM_2D: read2D(surface); break; case FX_SURFACE_TYPE_ENUM_3D: read3D(surface); break; case FX_SURFACE_TYPE_ENUM_RECT: readRect(surface); break; case FX_SURFACE_TYPE_ENUM_CUBE: readCube(surface); break; case FX_SURFACE_TYPE_ENUM_DEPTH: readDepth(surface); break; case FX_SURFACE_TYPE_ENUM_COUNT: SWARNING << "ColladaSurface::read FX_SURFACE_TYPE_ENUM_COUNT " << "not handled" << std::endl; break; } }
void checkReadWriteRoundTrip(KisPaintDeviceSP dev, const QRect &rc) { KisPaintDeviceSP deviceCopy = new KisPaintDevice(*dev.data()); QRect readRect(10, 10, 20, 20); int bufSize = rc.width() * rc.height() * dev->pixelSize(); QScopedPointer<quint8> buf1(new quint8[bufSize]); deviceCopy->readBytes(buf1.data(), rc); deviceCopy->clear(); QVERIFY(deviceCopy->extent().isEmpty()); QScopedPointer<quint8> buf2(new quint8[bufSize]); deviceCopy->writeBytes(buf1.data(), rc); deviceCopy->readBytes(buf2.data(), rc); QVERIFY(!memcmp(buf1.data(), buf2.data(), bufSize)); }
void UserInputServer::ansNormalizeRect(BlockingGate *backGate) { Rect rect = readRect(backGate); m_userInput->getNormalizedRect(&rect); sendRect(&rect, backGate); }
void DefineMorphShapeTag::read(SWFStream& in, TagType tag, movie_definition& md, const RunResources& r) { assert(tag == DEFINEMORPHSHAPE || tag == DEFINEMORPHSHAPE2 || tag == DEFINEMORPHSHAPE2_); const SWFRect bounds1 = readRect(in); const SWFRect bounds2 = readRect(in); if (tag == DEFINEMORPHSHAPE2 || tag == DEFINEMORPHSHAPE2_) { // TODO: Use these values. const SWFRect innerBound1 = readRect(in); const SWFRect innerBound2 = readRect(in); UNUSED(innerBound1); UNUSED(innerBound2); // This should be used -- first 6 bits reserved, then // 'non-scaling' stroke, then 'scaling' stroke -- these can be // used to optimize morphing. in.ensureBytes(1); static_cast<void>(in.read_u8()); } in.ensureBytes(4); // Offset. What is this for? static_cast<void>(in.read_u32()); // Next line will throw ParserException on malformed SWF const boost::uint16_t fillCount = in.read_variable_count(); for (size_t i = 0; i < fillCount; ++i) { OptionalFillPair fp = readFills(in, tag, md, true); _shape1.addFillStyle(fp.first); _shape2.addFillStyle(*fp.second); } const boost::uint16_t lineCount = in.read_variable_count(); LineStyle ls1, ls2; for (size_t i = 0; i < lineCount; ++i) { ls1.read_morph(in, tag, md, r, &ls2); _shape1.addLineStyle(ls1); _shape2.addLineStyle(ls2); } _shape1.read(in, tag, md, r); in.align(); _shape2.read(in, tag, md, r); // Set bounds as read in *this* tags rather then // the one computed from ShapeRecord parser // (does it make sense ?) _shape1.setBounds(bounds1); _shape2.setBounds(bounds2); // Starting bounds are the same as shape1 _bounds = bounds1; assert(_shape1.fillStyles().size() == _shape2.fillStyles().size()); assert(_shape1.lineStyles().size() == _shape2.lineStyles().size()); }
void KisPaintDeviceTest::testReadBytesWrapAround() { const KoColorSpace *cs = KoColorSpaceRegistry::instance()->rgb8(); KisPaintDeviceSP dev = createWrapAroundPaintDevice(cs); KoColor c1(Qt::red, cs); KoColor c2(Qt::green, cs); dev->setPixel(3, 3, c1); dev->setPixel(18, 18, c2); const int pixelSize = dev->pixelSize(); { QRect readRect(10, 10, 20, 20); QScopedPointer<quint8> buf(new quint8[readRect.width() * readRect.height() * pixelSize]); dev->readBytes(buf.data(), readRect); //dev->convertToQImage(0, readRect.x(), readRect.y(), readRect.width(), readRect.height()).save("final1.png"); QVERIFY(memcmp(buf.data() + (7 + readRect.width() * 7) * pixelSize, c2.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (8 + readRect.width() * 8) * pixelSize, c2.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (12 + readRect.width() * 12) * pixelSize, c1.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (13 + readRect.width() * 13) * pixelSize, c1.data(), pixelSize)); checkReadWriteRoundTrip(dev, readRect); } { // check weird case when the read rect is larger than wrap rect QRect readRect(10, 10, 30, 30); QScopedPointer<quint8> buf(new quint8[readRect.width() * readRect.height() * pixelSize]); dev->readBytes(buf.data(), readRect); //dev->convertToQImage(0, readRect.x(), readRect.y(), readRect.width(), readRect.height()).save("final2.png"); QVERIFY(memcmp(buf.data() + (7 + readRect.width() * 7) * pixelSize, c2.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (8 + readRect.width() * 8) * pixelSize, c2.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (12 + readRect.width() * 12) * pixelSize, c1.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (13 + readRect.width() * 13) * pixelSize, c1.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (27 + readRect.width() * 7) * pixelSize, c2.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (28 + readRect.width() * 8) * pixelSize, c2.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (7 + readRect.width() * 27) * pixelSize, c2.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (8 + readRect.width() * 28) * pixelSize, c2.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (27 + readRect.width() * 27) * pixelSize, c2.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (28 + readRect.width() * 28) * pixelSize, c2.data(), pixelSize)); checkReadWriteRoundTrip(dev, readRect); } { // even more large QRect readRect(10, 10, 40, 40); QScopedPointer<quint8> buf(new quint8[readRect.width() * readRect.height() * pixelSize]); dev->readBytes(buf.data(), readRect); //dev->convertToQImage(0, readRect.x(), readRect.y(), readRect.width(), readRect.height()).save("final3.png"); QVERIFY(memcmp(buf.data() + (7 + readRect.width() * 7) * pixelSize, c2.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (8 + readRect.width() * 8) * pixelSize, c2.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (12 + readRect.width() * 12) * pixelSize, c1.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (13 + readRect.width() * 13) * pixelSize, c1.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (27 + readRect.width() * 7) * pixelSize, c2.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (28 + readRect.width() * 8) * pixelSize, c2.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (7 + readRect.width() * 27) * pixelSize, c2.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (8 + readRect.width() * 28) * pixelSize, c2.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (27 + readRect.width() * 27) * pixelSize, c2.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (28 + readRect.width() * 28) * pixelSize, c2.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (32 + readRect.width() * 12) * pixelSize, c1.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (33 + readRect.width() * 13) * pixelSize, c1.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (12 + readRect.width() * 32) * pixelSize, c1.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (13 + readRect.width() * 33) * pixelSize, c1.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (32 + readRect.width() * 32) * pixelSize, c1.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (33 + readRect.width() * 33) * pixelSize, c1.data(), pixelSize)); checkReadWriteRoundTrip(dev, readRect); } { // check if the wrap rect contains the read rect entirely QRect readRect(1, 1, 10, 10); QScopedPointer<quint8> buf(new quint8[readRect.width() * readRect.height() * pixelSize]); dev->readBytes(buf.data(), readRect); //dev->convertToQImage(0, readRect.x(), readRect.y(), readRect.width(), readRect.height()).save("final4.png"); QVERIFY(memcmp(buf.data() + (1 + readRect.width() * 1) * pixelSize, c1.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (2 + readRect.width() * 2) * pixelSize, c1.data(), pixelSize)); checkReadWriteRoundTrip(dev, readRect); } { // check if the wrap happens only on vertical side of the rect QRect readRect(1, 1, 29, 10); QScopedPointer<quint8> buf(new quint8[readRect.width() * readRect.height() * pixelSize]); dev->readBytes(buf.data(), readRect); //dev->convertToQImage(0, readRect.x(), readRect.y(), readRect.width(), readRect.height()).save("final5.png"); QVERIFY(memcmp(buf.data() + (1 + readRect.width() * 1) * pixelSize, c1.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (2 + readRect.width() * 2) * pixelSize, c1.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (21 + readRect.width() * 1) * pixelSize, c1.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (22 + readRect.width() * 2) * pixelSize, c1.data(), pixelSize)); checkReadWriteRoundTrip(dev, readRect); } { // check if the wrap happens only on horizontal side of the rect QRect readRect(1, 1, 10, 29); QScopedPointer<quint8> buf(new quint8[readRect.width() * readRect.height() * pixelSize]); dev->readBytes(buf.data(), readRect); //dev->convertToQImage(0, readRect.x(), readRect.y(), readRect.width(), readRect.height()).save("final6.png"); QVERIFY(memcmp(buf.data() + (1 + readRect.width() * 1) * pixelSize, c1.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (2 + readRect.width() * 2) * pixelSize, c1.data(), pixelSize)); QVERIFY(memcmp(buf.data() + (1 + readRect.width() * 21) * pixelSize, c1.data(), pixelSize)); QVERIFY(!memcmp(buf.data() + (2 + readRect.width() * 22) * pixelSize, c1.data(), pixelSize)); checkReadWriteRoundTrip(dev, readRect); } }
bool World::loadWorld(Common::MacResManager *resMan) { Common::MacResIDArray resArray; Common::SeekableReadStream *res; Common::MacResIDArray::const_iterator iter; // Dumping interpreter code #if 1 res = resMan->getResource(MKTAG('C','O','D','E'), 1); warning("code size: %d", res->size()); byte *buf = (byte *)malloc(res->size()); res->read(buf, res->size()); Common::DumpFile out; out.open("code.bin"); out.write(buf, res->size()); out.close(); free(buf); delete res; #endif if ((resArray = resMan->getResIDArray(MKTAG('G','C','O','D'))).size() == 0) return false; // Load global script res = resMan->getResource(MKTAG('G','C','O','D'), resArray[0]); _globalScript = new Script(res); // TODO: read creator // Load main configuration if ((resArray = resMan->getResIDArray(MKTAG('V','E','R','S'))).size() == 0) return false; _name = resMan->getBaseFileName(); if (resArray.size() > 1) warning("Too many VERS resources"); if (!resArray.empty()) { debug(3, "Loading version info"); res = resMan->getResource(MKTAG('V','E','R','S'), resArray[0]); res->skip(10); byte b = res->readByte(); _weaponMenuDisabled = (b != 0); if (b != 0 && b != 1) error("Unexpected value for weapons menu"); res->skip(3); _aboutMessage = readPascalString(res); if (!scumm_stricmp(resMan->getBaseFileName().c_str(), "Scepters")) res->skip(1); // ???? _soundLibrary1 = readPascalString(res); _soundLibrary2 = readPascalString(res); delete res; } Common::String *message; if ((message = loadStringFromDITL(resMan, 2910, 1)) != NULL) { message->trim(); debug(2, "_gameOverMessage: %s", message->c_str()); _gameOverMessage = message; } if ((message = loadStringFromDITL(resMan, 2480, 3)) != NULL) { message->trim(); debug(2, "_saveBeforeQuitMessage: %s", message->c_str()); _saveBeforeQuitMessage = message; } if ((message = loadStringFromDITL(resMan, 2490, 3)) != NULL) { message->trim(); debug(2, "_saveBeforeCloseMessage: %s", message->c_str()); _saveBeforeCloseMessage = message; } if ((message = loadStringFromDITL(resMan, 2940, 2)) != NULL) { message->trim(); debug(2, "_revertMessage: %s", message->c_str()); _revertMessage = message; } // Load scenes resArray = resMan->getResIDArray(MKTAG('A','S','C','N')); debug(3, "Loading %d scenes", resArray.size()); for (iter = resArray.begin(); iter != resArray.end(); ++iter) { res = resMan->getResource(MKTAG('A','S','C','N'), *iter); Scene *scene = new Scene(resMan->getResName(MKTAG('A','S','C','N'), *iter), res); res = resMan->getResource(MKTAG('A','C','O','D'), *iter); if (res != NULL) scene->_script = new Script(res); res = resMan->getResource(MKTAG('A','T','X','T'), *iter); if (res != NULL) { scene->_textBounds = readRect(res); scene->_fontType = res->readUint16BE(); scene->_fontSize = res->readUint16BE(); Common::String text; while (res->pos() < res->size()) { char c = res->readByte(); if (c == 0x0d) c = '\n'; text += c; } scene->_text = text; delete res; } addScene(scene); } // Load Objects resArray = resMan->getResIDArray(MKTAG('A','O','B','J')); debug(3, "Loading %d objects", resArray.size()); for (iter = resArray.begin(); iter != resArray.end(); ++iter) { res = resMan->getResource(MKTAG('A','O','B','J'), *iter); addObj(new Obj(resMan->getResName(MKTAG('A','O','B','J'), *iter), res)); } // Load Characters resArray = resMan->getResIDArray(MKTAG('A','C','H','R')); debug(3, "Loading %d characters", resArray.size()); for (iter = resArray.begin(); iter != resArray.end(); ++iter) { res = resMan->getResource(MKTAG('A','C','H','R'), *iter); Chr *chr = new Chr(resMan->getResName(MKTAG('A','C','H','R'), *iter), res); addChr(chr); // TODO: What if there's more than one player character? if (chr->_playerCharacter) _player = chr; } // Load Sounds resArray = resMan->getResIDArray(MKTAG('A','S','N','D')); debug(3, "Loading %d sounds", resArray.size()); 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)); } if (!_soundLibrary1.empty()) { loadExternalSounds(_soundLibrary1); } if (!_soundLibrary2.empty()) { loadExternalSounds(_soundLibrary2); } // Load Patterns res = resMan->getResource(MKTAG('P','A','T','#'), 900); if (res != NULL) { int count = res->readUint16BE(); debug(3, "Loading %d patterns", count); for (int i = 0; i < count; i++) { byte *pattern = (byte *)malloc(8); res->read(pattern, 8); _patterns->push_back(pattern); } delete res; } else { /* Enchanted Scepters did not use the PAT# resource for the textures. */ res = resMan->getResource(MKTAG('C','O','D','E'), 1); if (res != NULL) { res->skip(0x55ac); for (int i = 0; i < 29; i++) { byte *pattern = (byte *)malloc(8); res->read(pattern, 8); _patterns->push_back(pattern); } } delete res; } res = resMan->getResource(MKTAG('M','E','N','U'), 2001); if (res != NULL) { Common::StringArray *menu = readMenu(res); _aboutMenuItemName.clear(); Common::String string = menu->operator[](1); for (uint i = 0; i < string.size() && string[i] != ';'; i++) // Read token _aboutMenuItemName += string[i]; delete menu; delete res; } res = resMan->getResource(MKTAG('M','E','N','U'), 2004); if (res != NULL) { Common::StringArray *menu = readMenu(res); _commandsMenuName = menu->operator[](0); _commandsMenu = menu->operator[](1); delete menu; delete res; } res = resMan->getResource(MKTAG('M','E','N','U'), 2005); if (res != NULL) { Common::StringArray *menu = readMenu(res); _weaponsMenuName = menu->operator[](0); delete menu; delete res; } // TODO: Read Apple menu and get the name of that menu item.. // store global info in state object for use with save/load actions //world.setCurrentState(initialState); // pass off the state object to the world return true; }
bool NSParser::readCallArg(Symbol *symbol, VariableList &variables, NSParser::DeclaredVariable& callArgVariable) { bool result = true; switch(symbol->symbolIndex) { case SYM_VAR: { QString name = readVar(symbol); if (variables.contains(name)) callArgVariable = variables[name]; else { addError(NSParsingError::undeclaredVariableError(name, symbol)); result = false; } break; } case SYM_POINT: case SYM_FIXED_POINT: { Tools::RPoint p = readPoint(symbol); callArgVariable = DeclaredVariable::fromPoint(p); break; } case SYM_RECT2: case SYM_FIXED_RECT: { QRectF r = readRect(symbol, variables); callArgVariable = DeclaredVariable::fromRect(r); break; } case SYM_SENSOR_IDENTIFIER: { int type = -1, id = 0; readSensorIdentifier(symbol, type, id); callArgVariable = DeclaredVariable::fromSensor(id, type); break; } case SYM_PARAMETER_IDENTIFIER: { int paramId = readSubId(symbol); callArgVariable = DeclaredVariable::fromParameter(paramId); break; } case SYM_AX12_IDENTIFIER: { int ax12Id = readSubId(symbol); callArgVariable = DeclaredVariable::fromAx12(ax12Id); break; } case SYM_ACTION2: { int actionId, param, time; readAction(symbol, actionId, param, time); callArgVariable = DeclaredVariable::fromAction(actionId, param, time); break; } case SYM_STRING: { QString str = readString(symbol); callArgVariable = DeclaredVariable::fromString(str); break; } case SYM_CALLARG: { if (symbol->type == NON_TERMINAL) { result = false; NonTerminal* nt = static_cast<NonTerminal*>(symbol); for(Symbol* child: nt->children) { readCallArg(child, variables, callArgVariable); if (callArgVariable.isValid()) { result = true; break; } } } } } return result; }
Chr::Chr(Common::String name, Common::SeekableReadStream *data) { _name = name; _classType = CHR; _design = new Design(data); _index = 0; _resourceId = 0; _currentScene = NULL; setDesignBounds(readRect(data)); _physicalStrength = data->readByte(); _physicalHp = data->readByte(); _naturalArmor = data->readByte(); _physicalAccuracy = data->readByte(); _spiritualStength = data->readByte(); _spiritialHp = data->readByte(); _resistanceToMagic = data->readByte(); _spiritualAccuracy = data->readByte(); _runningSpeed = data->readByte(); _rejectsOffers = data->readByte(); _followsOpponent = data->readByte(); data->readSByte(); // TODO: ??? data->readSint32BE(); // TODO: ??? _weaponDamage1 = data->readByte(); _weaponDamage2 = data->readByte(); data->readSByte(); // TODO: ??? if (data->readSByte() == 1) _playerCharacter = true; else _playerCharacter = false; _maximumCarriedObjects = data->readByte(); _returnTo = data->readSByte(); _winningWeapons = data->readByte(); _winningMagic = data->readByte(); _winningRun = data->readByte(); _winningOffer = data->readByte(); _losingWeapons = data->readByte(); _losingMagic = data->readByte(); _losingRun = data->readByte(); _losingOffer = data->readByte(); _gender = data->readSByte(); if (data->readSByte() == 1) _nameProperNoun = true; else _nameProperNoun = false; _initialScene = readPascalString(data); _nativeWeapon1 = readPascalString(data); _operativeVerb1 = readPascalString(data); _nativeWeapon2 = readPascalString(data); _operativeVerb2 = readPascalString(data); _initialComment = readPascalString(data); _scoresHitComment = readPascalString(data); _receivesHitComment = readPascalString(data); _makesOfferComment = readPascalString(data); _rejectsOfferComment = readPascalString(data); _acceptsOfferComment = readPascalString(data); _dyingWords = readPascalString(data); _initialSound = readPascalString(data); _scoresHitSound = readPascalString(data); _receivesHitSound = readPascalString(data); _dyingSound = readPascalString(data); _weaponSound1 = readPascalString(data); _weaponSound2 = readPascalString(data); for (int i = 0; i < NUMBER_OF_ARMOR_TYPES; i++) _armor[i] = NULL; _weapon1 = NULL; _weapon2 = NULL; // Create native weapons if (!_nativeWeapon1.empty() && !_operativeVerb1.empty()) { _weapon1 = new Obj; _weapon1->_name = _nativeWeapon1; _weapon1->_operativeVerb = _operativeVerb1; _weapon1->_type = Obj::REGULAR_WEAPON; _weapon1->_accuracy = 0; _weapon1->_damage = _weaponDamage1; _weapon1->_sound = _weaponSound1; } if (!_nativeWeapon2.empty() && !_operativeVerb2.empty()) { _weapon2 = new Obj; _weapon2->_name = _nativeWeapon2; _weapon2->_operativeVerb = _operativeVerb2; _weapon2->_type = Obj::REGULAR_WEAPON; _weapon2->_accuracy = 0; _weapon2->_damage = _weaponDamage2; _weapon2->_sound = _weaponSound2; } delete data; }
Graphics::Surface *CDToonsDecoder::decodeImage(Common::SeekableReadStream *stream) { uint16 u0 = stream->readUint16BE(); // always 9? uint16 frameId = stream->readUint16BE(); uint16 blocksValidUntil = stream->readUint16BE(); byte u6 = stream->readByte(); byte backgroundColor = stream->readByte(); debugN(5, "CDToons frame %d, size %d, unknown %04x (at 0), blocks valid until %d, unknown 6 is %02x, bkg color is %02x\n", frameId, stream->size(), u0, blocksValidUntil, u6, backgroundColor); Common::Rect clipRect = readRect(stream); debugN(9, "CDToons clipRect: (%d, %d) to (%d, %d)\n", clipRect.left, clipRect.top, clipRect.right, clipRect.bottom); Common::Rect dirtyRect = readRect(stream); debugN(9, "CDToons dirtyRect: (%d, %d) to (%d, %d)\n", dirtyRect.left, dirtyRect.top, dirtyRect.right, dirtyRect.bottom); uint32 flags = stream->readUint32BE(); if (flags & 0x80) error("CDToons: frame already processed?"); debugN(5, "CDToons flags: %08x\n", flags); uint16 blockCount = stream->readUint16BE(); uint16 blockOffset = stream->readUint16BE(); debugN(9, "CDToons: %d blocks at 0x%04x\n", blockCount, blockOffset); // max block id? uint16 u32 = stream->readUint16BE(); debugN(5, "CDToons unknown at 32: %04x\n", u32); byte actionCount = stream->readByte(); byte u35 = stream->readByte(); uint16 paletteId = stream->readUint16BE(); byte paletteSet = stream->readByte(); debugN(9, "CDToons palette id %04x, palette byte %02x\n", paletteId, paletteSet); byte u39 = stream->readByte(); uint16 u40 = stream->readUint16BE(); uint16 u42 = stream->readUint16BE(); debugN(5, "CDToons: unknown at 35 is %02x, unknowns at 39: %02x, %04x, %04x\n", u35, u39, u40, u42); Common::Array<CDToonsAction> actions; for (uint i = 0; i < actionCount; i++) { CDToonsAction action; action.blockId = stream->readUint16BE(); action.rect = readRect(stream); debugN(9, "CDToons action: render block %d at (%d, %d) to (%d, %d)\n", action.blockId, action.rect.left, action.rect.top, action.rect.right, action.rect.bottom); actions.push_back(action); } if (stream->pos() > blockOffset) error("CDToons header ended at 0x%08x, but blocks should have started at 0x%08x", stream->pos(), blockOffset); if (stream->pos() != blockOffset) error("CDToons had %d unknown bytes after header", blockOffset - stream->pos()); for (uint i = 0; i < blockCount; i++) { uint16 blockId = stream->readUint16BE(); if (blockId >= 1200) error("CDToons: block id %d was too high", blockId); if (_blocks.contains(blockId)) error("CDToons: new block %d was already seen", blockId); CDToonsBlock block; block.flags = stream->readUint16BE(); // flag 1 = palette, flag 2 = data? if (block.flags & 0x8000) error("CDToons: block already processed?"); block.size = stream->readUint32BE(); if (block.size < 14) error("CDToons: block size was %d, too small", block.size); block.size -= 14; block.startFrame = stream->readUint16BE(); block.endFrame = stream->readUint16BE(); block.unknown12 = stream->readUint16BE(); block.data = new byte[block.size]; stream->read(block.data, block.size); debugN(9, "CDToons block id 0x%04x of size 0x%08x, flags %04x, from frame %d to %d, unknown at 12 is %04x\n", blockId, block.size, block.flags, block.startFrame, block.endFrame, block.unknown12); _blocks[blockId] = block; } byte xFrmBegin = 0, xFrmCount; Common::Array<CDToonsDiff> diffs; while (true) { int32 nextPos = stream->pos(); uint32 tag = stream->readUint32BE(); uint32 size = stream->readUint32BE(); nextPos += size; switch (tag) { case MKTAG('D','i','f','f'): { debugN(5, "CDToons: Diff\n"); uint16 count = stream->readUint16BE(); Common::Rect diffClipRect = readRect(stream); debugN(9, "CDToons diffClipRect: (%d, %d) to (%d, %d)\n", diffClipRect.left, diffClipRect.top, diffClipRect.right, diffClipRect.bottom); debugN(5, "CDToons Diff: %d subentries\n", count); for (uint i = 0; i < count; i++) { CDToonsDiff diff; diff.rect = readRect(stream); diff.size = stream->readUint32BE(); if (diff.size < 20) error("CDToons: Diff block size was %d, too small", diff.size); uint16 diffWidth = stream->readUint16BE(); uint16 diffHeight = stream->readUint16BE(); uint16 unknown16 = stream->readUint16BE(); uint16 unknown18 = stream->readUint16BE(); diff.size -= 8; if (diffWidth != diff.rect.width() || diffHeight != diff.rect.height()) error("CDToons: Diff sizes didn't match"); debugN(5, "CDToons Diff: size %d, frame from (%d, %d) to (%d, %d), unknowns %04x, %04x\n", diff.size, diff.rect.left, diff.rect.top, diff.rect.right, diff.rect.bottom, unknown16, unknown18); diff.data = new byte[diff.size]; stream->read(diff.data, diff.size); diffs.push_back(diff); } } break; case MKTAG('X','F','r','m'): { debugN(5, "CDToons: XFrm\n"); if (!(flags & 0x10)) error("CDToons: useless XFrm?"); if (xFrmBegin) error("CDToons: duplicate XFrm"); xFrmBegin = stream->readByte(); xFrmCount = stream->readByte(); debugN(9, "CDToons XFrm: run %d actions from %d\n", xFrmCount, xFrmBegin - 1); // TODO: don't ignore (if xFrmCount is non-zero) Common::Rect dirtyRectXFrm = readRect(stream); debugN(9, "CDToons XFrm dirtyRect: (%d, %d) to (%d, %d)\n", dirtyRectXFrm.left, dirtyRectXFrm.top, dirtyRectXFrm.right, dirtyRectXFrm.bottom); // always zero? Common::Rect dirtyRect2XFrm = readRect(stream); debugN(9, "CDToons XFrm dirtyRect2: (%d, %d) to (%d, %d)\n", dirtyRect2XFrm.left, dirtyRect2XFrm.top, dirtyRect2XFrm.right, dirtyRect2XFrm.bottom); } break; case MKTAG('M','r','k','s'): debugN(5, "CDToons: Mrks\n"); if (!(flags & 0x2)) error("CDToons: useless Mrks?"); // TODO warning("CDToons: encountered Mrks, not implemented yet"); break; case MKTAG('S','c','a','l'): // TODO warning("CDToons: encountered Scal, not implemented yet"); break; case MKTAG('W','r','M','p'): warning("CDToons: encountered WrMp, ignoring"); break; case MKTAG('F','r','t','R'): { debugN(5, "CDToons: FrtR\n"); if (!(flags & 0x40)) error("CDToons: useless FrtR?"); uint16 count = stream->readUint16BE(); debugN(9, "CDToons FrtR: %d dirty rectangles\n", count); for (uint i = 0; i < count; i++) { Common::Rect dirtyRectFrtR = readRect(stream); debugN(9, "CDToons FrtR dirtyRect: (%d, %d) to (%d, %d)\n", dirtyRectFrtR.left, dirtyRectFrtR.top, dirtyRectFrtR.right, dirtyRectFrtR.bottom); } } break; case MKTAG('B','c','k','R'): { debugN(5, "CDToons: BckR\n"); if (!(flags & 0x20)) error("CDToons: useless BckR?"); uint16 count = stream->readUint16BE(); debugN(9, "CDToons BckR: %d subentries\n", count); for (uint i = 0; i < count; i++) { Common::Rect dirtyRectBckR = readRect(stream); debugN(9, "CDToons BckR dirtyRect: (%d, %d) to (%d, %d)\n", dirtyRectBckR.left, dirtyRectBckR.top, dirtyRectBckR.right, dirtyRectBckR.bottom); } } break; default: warning("Unknown CDToons tag '%s'", tag2str(tag)); } if (stream->pos() > nextPos) error("CDToons ran off the end of a block while reading it (at %d, next block at %d)", stream->pos(), nextPos); if (stream->pos() != nextPos) { warning("CDToons had %d unknown bytes after block", nextPos - stream->pos()); stream->seek(nextPos); } if (stream->pos() == stream->size()) break; } for (uint i = 0; i < diffs.size(); i++) { renderBlock(diffs[i].data, diffs[i].size, diffs[i].rect.left, diffs[i].rect.top, diffs[i].rect.width(), diffs[i].rect.height()); delete[] diffs[i].data; } if (!diffs.empty()) return _surface; for (uint i = 0; i < actions.size(); i++) { CDToonsAction &action = actions[i]; if (i == 0 && action.blockId == 0) memset(_surface->pixels, backgroundColor, _surface->w * _surface->h); if (!_blocks.contains(action.blockId)) continue; if (!action.rect.right) continue; if (i == 0 && !diffs.empty()) continue; CDToonsBlock &block = _blocks[action.blockId]; uint16 width = READ_BE_UINT16(block.data + 2); uint16 height = READ_BE_UINT16(block.data); renderBlock(block.data + 14, block.size - 14, action.rect.left, action.rect.top, width, height); } if (paletteId && _currentPaletteId != paletteId) { if (!_blocks.contains(paletteId)) error("CDToons: no block for palette %04x", paletteId); if (_blocks[paletteId].size != 2 * 3 * 256) error("CDToons: palette %04x is wrong size (%d)", paletteId, _blocks[paletteId].size); _currentPaletteId = paletteId; if (!paletteSet) setPalette(_blocks[paletteId].data); } return _surface; }
int readMovie(ddReader* r) { ddRect bounds; ddMovieClip* p = r->playclip; int byte = readUInt8(r); if ( byte == 'C' ) { #ifdef HAVE_ZLIB // file is compressed unsigned char* buf = NULL; unsigned char* dest; unsigned long size; int len = 0; if ( readUInt8(r) != 'W' || readUInt8(r) != 'S' ) return -1; r->version = readUInt8(r); size = readUInt32(r); dest = dd_malloc(size); // XXX - should do this in a streaming way while ( !ddReader_isEOF(r) ) { if ( len % 1024 == 0 ) buf = dd_realloc(buf, len + 1024); buf[len++] = readUInt8(r); } if ( uncompress(dest, &size, buf, len) != Z_OK ) return -1; ddReader_setBuffer(r, (char*)dest, size); p->bytesTotal = size; p->bytesTotal = r->filesize = size; #else return -1; #endif } else { if ( byte != 'F' || readUInt8(r) != 'W' || readUInt8(r) != 'S' ) return -1; r->version = readUInt8(r); p->bytesTotal = r->filesize = readUInt32(r); } p->bytesLoaded = p->bytesTotal; // XXX bounds = readRect(r); ddMovieClip_setWidth(p, ddRect_getWidth(bounds)); ddMovieClip_setHeight(p, ddRect_getHeight(bounds)); r->frameRate = readUInt8(r) / 256.0; r->frameRate += readUInt8(r); p->framesTotal = readUInt16(r); for ( ;; ) { int offset = ddReader_getOffset(r); int nextoffset; int block = readUInt16(r); Blocktype type = block >> 6; int length = block & ((1 << 6) - 1); if ( length == 63 ) /* it's a long block. */ length = readUInt32(r); nextoffset = ddReader_getOffset(r) + length; if ( type == 0 || ddReader_getOffset(r) >= r->filesize || length < 0 ) return 0; switch ( type ) { case DEFINESHAPE: readDefineShape(p, r, length); break; case DEFINESHAPE2: readDefineShape2(p, r, length); break; case DEFINESHAPE3: readDefineShape3(p, r, length); break; case DEFINEMORPHSHAPE: readDefineMorphShape(p, r, length); break; case PLACEOBJECT: readPlaceObject(p, r, length); break; case PLACEOBJECT2: readPlaceObject2(p, r, length); break; case REMOVEOBJECT: readRemoveObject(p, r, length); break; case REMOVEOBJECT2: readRemoveObject2(p, r, length); break; case SHOWFRAME: readShowFrame(p, r, length); break; case DEFINELOSSLESS: readDefineBitsLossless(p, r, length, 1); break; case DEFINELOSSLESS2: readDefineBitsLossless(p, r, length, 2); break; case JPEGTABLES: { int hoge = 0; } #if HAVE_JPEGLIB readJpegTables(p, r, length); #endif break; case DEFINEBITS: readDefineBitsJpeg(p, r, length); break; case DEFINEBITSJPEG2: readDefineBitsJpeg2(p, r, length); break; case DEFINEBITSJPEG3: readDefineBitsJpeg3(p, r, length); break; case DEFINETEXT: readDefineText(p, r, length); break; case DEFINETEXT2: readDefineText2(p, r, length); break; case DEFINEFONTINFO: readFontInfo(p, r, length); break; case DEFINEFONTINFO2: readFontInfo2(p, r, length); break; case DEFINEFONT: readDefineFont(p, r, length); break; case DEFINEFONT2: readDefineFont2(p, r, length); break; case DEFINESPRITE: readDefineSprite(p, r, length); break; case SETBACKGROUNDCOLOR: readBackgroundColor(p, r, length); break; case FRAMELABEL: readFrameLabel(p, r, length); break; case DOACTION: readClipAction(p, r, length); break; case INITCLIPACTION: readInitClipAction(p, r, length); break; case DEFINEBUTTON: readDefineButton(p, r, length); break; case DEFINEBUTTON2: readDefineButton2(p, r, length); break; case LIBRARYSYMBOL: readLibrarySymbol(p, r, length); break; case TEXTFIELD: readTextField(p, r, length); break; case DEFINESOUND: readDefineSound(p, r, length); break; case STARTSOUND: readStartSound(p, r, length); break; case DEFINEBUTTONSOUND: skipBytes(r, length); break; case SOUNDSTREAMHEAD: case SOUNDSTREAMHEAD2: readSoundStreamHead(p, r, length); break; case SOUNDSTREAMBLOCK: readSoundStreamBlock(p, r, length); break; case PROTECT: case PASSWORD: skipBytes(r, length); break; default: dd_warn("Unrecognized block at 0x%x: type %i, length %i\n", offset, type, length); skipBytes(r, length); } ddReader_setOffset(r, nextoffset); } return 0; }