Exemplo n.º 1
0
Arquivo: udif.c Projeto: 1butler1/xpwn
void readUDIFResourceFile(AbstractFile* file, UDIFResourceFile* o) {
  o->fUDIFSignature = readUInt32(file);
  
  ASSERT(o->fUDIFSignature == 0x6B6F6C79, "readUDIFResourceFile - signature incorrect");
  
  o->fUDIFVersion = readUInt32(file);
  o->fUDIFHeaderSize = readUInt32(file);
  o->fUDIFFlags = readUInt32(file);
  
  o->fUDIFRunningDataForkOffset = readUInt64(file);
  o->fUDIFDataForkOffset = readUInt64(file);
  o->fUDIFDataForkLength = readUInt64(file);
  o->fUDIFRsrcForkOffset = readUInt64(file);
  o->fUDIFRsrcForkLength = readUInt64(file);
  
  o->fUDIFSegmentNumber = readUInt32(file);
  o->fUDIFSegmentCount = readUInt32(file);
  readUDIFID(file, &(o->fUDIFSegmentID));
  
  readUDIFChecksum(file, &(o->fUDIFDataForkChecksum));
  
  o->fUDIFXMLOffset = readUInt64(file);
  o->fUDIFXMLLength = readUInt64(file);
  
  ASSERT(file->read(file, &(o->reserved1), 0x78) == 0x78, "fread");
  
  readUDIFChecksum(file, &(o->fUDIFMasterChecksum));
  
  o->fUDIFImageVariant = readUInt32(file);
  o->fUDIFSectorCount = readUInt64(file);
  
  o->reserved2 = readUInt32(file);
  o->reserved3 = readUInt32(file);
  o->reserved4 = readUInt32(file);
}
Exemplo n.º 2
0
void printSoundInfo(FILE *f)
{
  int flags = readUInt8(f), nPoints, i;

  ++gIndent;

  if(flags&0x40)
    println("Don't start if already playing");

  if(flags&0x80)
    println("Stop sound");

  if(flags&0x01)
    println("In Point: %i", readUInt32(f));

  if(flags&0x02)
    println("Out Point: %i", readUInt32(f));

  if(flags&0x04)
    println("Loops: %i", readUInt16(f));

  if(flags&0x08)
  {
    nPoints = readUInt8(f);
    for(i=0; i<nPoints; ++i)
    {
      println("Envelope point %i:", i);
      println("Mark44: %i", readUInt32(f));
      println("Level0: %i", readUInt16(f));
      println("Level1: %i", readUInt16(f));
    }
  }

  --gIndent;
}
Exemplo n.º 3
0
bool CCMIAdapter::queryChip()
{
	PAGED_CODE();
	DBGPRINT(("CCMIAdapter[%p]::queryChip()", this));

	UInt32 version = readUInt32(REG_INTHLDCLR) & VERSION_MASK;
	if (version == 0xFFFFFFFF) {
		return false;
	}
	if (version) {
		if (version & VERSION_68) {
			cm.chipVersion = 68;
			cm.maxChannels = 8;
			cm.canAC3HW = true;
			cm.hasDualDAC = true;
			cm.canMultiChannel = true;
			return true;
		}
		if (version & VERSION_55) {
			cm.chipVersion = 55;
			cm.maxChannels = 6;
			cm.canAC3HW = true;
			cm.hasDualDAC = true;
			cm.canMultiChannel = true;
			return true;
		}
		if (version & VERSION_39) {
			cm.chipVersion = 39;
			if (version & VERSION_39_6) {
				cm.maxChannels = 6;
			} else {
				cm.maxChannels = 4;
			}
			cm.canAC3HW = true;
			cm.hasDualDAC = true;
			cm.canMultiChannel = true;
			return true;
		}
	} else {
		version = readUInt32(REG_CHFORMAT) & VERSION_37;
		if (!version) {
			cm.chipVersion = 33;
			cm.maxChannels = 2;
			if (cm.doAC3SW) {
				cm.canAC3SW = true;
			} else {
				cm.canAC3HW = true;
			}
			cm.hasDualDAC = true;
			return true;
		} else {
			cm.chipVersion = 37;
			cm.maxChannels = 2;
			cm.canAC3HW = true;
			cm.hasDualDAC = 1;
			return true;
		}
	}
	return false;
}
Exemplo n.º 4
0
void printSoundInstance(FILE *f, int id, int soundid){
  int e,point,left,right;
	int flags = readUInt8(f);

	if (flags & SWFSOUNDINFO_SYNCSTOPSOUND){
		printf("\t# stopsound??");
	}
	if (flags & SWFSOUNDINFO_SYNCNOMULTIPLE){
		printf("\t$si->setNoMultiple();\n");
	}
	if(flags & SWFSOUNDINFO_HASINPOINT){
		int inpoint = readUInt32(f);
		printf("\t$si->setInPoint(%i);\n", inpoint);
	}
	if(flags & SWFSOUNDINFO_HASOUTPOINT){
		int outpoint = readUInt32(f);
		printf("\t$si->setOutPoint(%i);\n", outpoint);               
	}
	if(flags & SWFSOUNDINFO_HASLOOPS){
		int loopcount = readUInt16(f);
		printf("\t$si->setLoops(%i);\n", loopcount);
	}
	if(flags & SWFSOUNDINFO_HASENVELOPE) {
		int envpoints = readUInt8(f);
		for (e=0; e<envpoints;e++){
			point = readUInt32(f);
			left  = readUInt16(f);
			left  = readUInt16(f);
			printf("\t$si->addEnvelopePoint(%i,%i,%i);\n", point,left,right);
		}
	}
} 
Exemplo n.º 5
0
Arquivo: udif.c Projeto: 1butler1/xpwn
void readUDIFChecksum(AbstractFile* file, UDIFChecksum* o) {
  int i;
  
  o->type = readUInt32(file);
  o->size = readUInt32(file);
  
  for(i = 0; i < 0x20; i++) {
    o->data[i] = readUInt32(file);
  }
}
Exemplo n.º 6
0
bool isWOFF(SharedBuffer* buffer)
{
    size_t offset = 0;
    uint32_t signature;

    return readUInt32(buffer, offset, signature) && signature == woffSignature;
}
        //----------------------------------------------------------------------
        void
        WalkmeshFileSerializer::importWalkmeshFile( Ogre::DataStreamPtr &stream
                                                   ,WalkmeshFile *pDest )
        {
            uint32 triangle_count( 0 );
            readUInt32( stream, triangle_count );

            TriangleList triangles;
            readVector( stream, triangles, triangle_count );

            AccessList access;
            readVector( stream, access, triangle_count );

            WalkmeshTriangleList   &triangle_list( pDest->getTriangles() );
            triangle_list.clear();
            triangle_list.reserve( triangle_count );

            for( uint32 i(0); i < triangle_count; ++i )
            {
                Triangle   &in_triangle( triangles[i] );
                Access     &in_access( access[i] );
                WalkmeshTriangle tmp_triangle;
                tmp_triangle.a = in_triangle.a;
                tmp_triangle.b = in_triangle.b;
                tmp_triangle.c = in_triangle.c;
                tmp_triangle.access_side[0] = in_access.a;
                tmp_triangle.access_side[1] = in_access.b;
                tmp_triangle.access_side[2] = in_access.c;
                triangle_list.push_back( tmp_triangle );
            }
        }
Exemplo n.º 8
0
void BaseSerializedObj::readUInt32Array(uint32_t** o)
{
    uint64_t size = readUInt64();
    *o = (uint32_t *) malloc(size*byteSize_writeInt32);
    uint64_t i = 0;
    while(i != size)
    {
        (*o)[i] = readUInt32();
        i++;
    }
}
Exemplo n.º 9
0
void printPlaceObject2(FILE *f, int length)
{
  int start = fileOffset;
  int flags = readUInt8(f);
  int l;

  println("Depth: %i", readUInt16(f));

  if(flags & PLACE_HASMOVE)
    println("Has move flag");

  if(flags & PLACE_HASCHARACTER)
    println("Character ID: %i", readUInt16(f));

  if(flags & PLACE_HASMATRIX)
  {
    println("Matrix:");
    printMatrix(f);
  }

  if(flags & PLACE_HASCXFORM)
  {
    print("CXForm: ");
    printCXForm(f, true);
    putchar('\n');
  }

  if(flags & PLACE_HASRATIO)
    println("Ratio: %i", readUInt16(f));

  if(flags & PLACE_HASNAME)
    println("Name: %s", readString(f));

  if(flags & PLACE_HASCLIP)
    println("ClipDepth: %i", readUInt16(f));

  if(flags & PLACE_RESERVED)
  {
    println("Mystery number: %04x", readUInt16(f));

    flags = readUInt16(f);
    println("Clip flags: %04x", flags);

    while((flags = readUInt16(f)) != 0)
    {
      println("Flags: %04x", flags);
      l = readUInt32(f);
      decompileAction(f, l, 0);
    }
  }

  dumpBytes(f, length-(fileOffset-start));
}
Exemplo n.º 10
0
void DataInputStream::readUTF8(StringStorage *storage)
{
  UINT32 sizeInBytes = readUInt32();
  if (sizeInBytes > 0) {
    std::vector<char> buffer(sizeInBytes);
    readFully(&buffer.front(), sizeInBytes);
    Utf8StringStorage utf8String(&buffer);
    utf8String.toStringStorage(storage);
  } else {
    storage->setString(_T(""));
  }
}
Exemplo n.º 11
0
int GameState::readFloat(float* pFloat) {
	union {
		uint32_t ul;
		float ft;
	} float_union;

	if (readUInt32(&float_union.ul))
		return -1;		// error retrieving 32-bits value

	*pFloat = float_union.ft;
	return 0;
}
Exemplo n.º 12
0
ddSoundInstance*
readSoundInfo(ddReader* r, int characterid)
{
	int flags = readUInt8(r);
	ddSoundInstance* sound;
	
	if ( (flags & SOUNDINFO_STOP) != 0 )
		return NULL;
	
	sound = dd_newSoundInstance(characterid);
	
	ddSoundInstance_setNoMultipleFlag(sound, (flags & SOUNDINFO_NOMULTIPLE) ? DD_TRUE : DD_FALSE);

	if ( (flags & SOUNDINFO_HASINPOINT) != 0 )
		ddSoundInstance_setInPoint(sound, readUInt32(r));
	
	if ( (flags & SOUNDINFO_HASOUTPOINT) != 0 )
		ddSoundInstance_setOutPoint(sound, readUInt32(r));
	
	if ( (flags & SOUNDINFO_HASLOOPS) != 0 )
		ddSoundInstance_setLoopCount(sound, readUInt16(r));
	
	if ( (flags & SOUNDINFO_HASENVELOPE) != 0 )
	{
		int count = readUInt8(r);
		int i;
		
		for ( i = 0; i < count; ++i )
		{
			int position = readUInt32(r);
			float leftLevel = (float)readUInt16(r) / 0xffff;
			float rightLevel = (float)readUInt16(r) / 0xffff;
			
			ddSoundInstance_addEnvelopePoint(sound, position, leftLevel, rightLevel);
		}
	}
	
	return sound;
}
Exemplo n.º 13
0
void
readDefineSound(ddMovieClip* p, ddReader* r, int length)
{
	int end = ddReader_getOffset(r) + length;
	int characterID = readUInt16(r);
	int flags = readUInt8(r);
	
	ddSoundFormat format;
	int sampleCount;
	unsigned char* data;
	int sampleRate;
	int bitsPerSample;
	boolean stereo;
	int delay;
	int size;
	ddSound* sound;
	
	switch ( (flags & 0xf0) >> 4 )
	{
		case 0: format = DDSOUND_UNCOMPRESSED; break;
		case 1: format = DDSOUND_ADPCM; break;
		case 2: format = DDSOUND_MP3; break;
		case 3: format = DDSOUND_UNCOMPRESSED_LITTLEENDIAN; break;
		case 6: format = DDSOUND_NELLYMOSER; break;
		default: dd_warn("Unknown sound format: %i", (flags & 0xf0) >> 4);
	}
	
	sampleCount = readUInt32(r);
	
	if ( format == DDSOUND_MP3 )
		delay = readSInt16(r);
	
	size = end - ddReader_getOffset(r);
	
	data = readBlock(r, size);
	
	switch ( (flags & 0x0c) >> 2 )
	{
		case 0: sampleRate = 5500; break;
		case 1: sampleRate = 11000; break;
		case 2: sampleRate = 22000; break;
		case 3: sampleRate = 44000; break;
	}
	
	bitsPerSample = ((flags & 0x02) != 0) ? 16 : 8;
	stereo = ((flags & 0x01) != 0) ? DD_TRUE : DD_FALSE;
	
	sound = dd_newSound(format, sampleRate, bitsPerSample, stereo, sampleCount, size, data, delay);

	ddMovieClip_addCharacter(p, characterID, (ddCharacter*)sound);
}
Exemplo n.º 14
0
void
IClipboard::unmarshall(IClipboard* clipboard, const CString& data, Time time)
{
	assert(clipboard != NULL);

	const char* index = data.data();

	// clear existing data
	clipboard->open(time);
	clipboard->empty();

	// read the number of formats
	const UInt32 numFormats = readUInt32(index);
	index += 4;

	// read each format
	for (UInt32 i = 0; i < numFormats; ++i) {
		// get the format id
		IClipboard::EFormat format =
			static_cast<IClipboard::EFormat>(readUInt32(index));
		index += 4;

		// get the size of the format data
		UInt32 size = readUInt32(index);
		index += 4;

		// save the data if it's a known format.  if either the client
		// or server supports more clipboard formats than the other
		// then one of them will get a format >= kNumFormats here.
		if (format <IClipboard::kNumFormats) {
			clipboard->add(format, CString(index, size));
		}
		index += size;
	}

	// done
	clipboard->close();
}
Exemplo n.º 15
0
void printDefineBitsJpeg3(FILE *f, int length)
{
  int offset;

  println("Bitmap id: %i", readUInt16(f));

  offset = readUInt32(f);

  printJpegStream(f, offset);

  putchar('\n');
  println("zlib-compressed alpha data:");

  skipBytes(f, length-offset-6);
}
Exemplo n.º 16
0
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);
}
Exemplo n.º 17
0
void printMorphShape(FILE *f, int length)
{
  int offset, start = fileOffset;
  int fillBits, lineBits, here;

  println("ShapeID: %i", readUInt16(f));

  print("Bounds1: ");
  printRect(f);
  putchar('\n');
  print("Bounds2: ");
  printRect(f);
  putchar('\n');

  offset = readUInt32(f);
  println("(%i)\toffset = %i", fileOffset, offset);

  here = fileOffset;

  printFillStyleArray(f, SWF_DEFINEMORPHSHAPE);
  printLineStyleArray(f, SWF_DEFINEMORPHSHAPE);

  fillBits = readBits(f, 4);
  lineBits = readBits(f, 4);

  putchar('\n');
  println("Shape1:");
  while(fileOffset < here+offset)
    printShapeRec(f, &lineBits, &fillBits, SWF_DEFINESHAPE3);

  byteAlign();

  /* ??? */
  fillBits = readBits(f, 4);
  lineBits = readBits(f, 4);

  putchar('\n');
  println("Shape2:");
  while(fileOffset < start+length)
    printShapeRec(f, &lineBits, &fillBits, SWF_DEFINESHAPE3);
}
void
OgreMeshReader::readGeometry(VertexElementStore &vertexElements)
{
    OSG_OGRE_LOG(("OgreMeshReader::readGeometry\n"));

    UInt32          vertCount = readUInt32(_is);
    BufferVertexMap bufferMap;

    OSG_OGRE_LOG(("OgreMeshReader::readGeometry: vertCount '%d'\n", vertCount));

    bool stop = false;

    while(_is)
    {
        readChunkHeader(_is);

        switch(_header.chunkId)
        {
        case CHUNK_GEOMETRY_VERTEX_DECLARATION:
            readGeometryVertexDeclaration(vertexElements, bufferMap);
            break;

        case CHUNK_GEOMETRY_VERTEX_BUFFER:
            readGeometryVertexBuffer(vertCount, vertexElements, bufferMap);
            break;

        default:
            OSG_OGRE_LOG(("OgreMeshReader::readGeometry: Unknown chunkId '0x%x'\n",
                          _header.chunkId));
            stop = true;
            break;
        };

        if(stop == true)
        {
            skip(_is, -_chunkHeaderSize);
            break;
        }
    }
}
void
OgreMeshReader::readMeshLODGenerated(void)
{
    OSG_OGRE_LOG(("OgreMeshReader::readMeshLODGenerated\n"));

    UInt32 idxCount = readUInt32(_is);
    bool   idx32Bit = readBool  (_is);

    if(idx32Bit == true)
    {
        // XXX TODO read index
        skip(_is, idxCount * sizeof(UInt32));
    }
    else
    {
        // XXX TODO read index
        skip(_is, idxCount * sizeof(UInt16));
    }

    SWARNING << "OgreMeshReader::readMeshLODManual: CHUNK_MESH_LOD_GENERATED NIY"
             << std::endl;
}
void
OgreMeshReader::readBoneAssignment(VertexElementStore &vertexElements,
                                   Int16              &boneIdxVE,
                                   Int16              &boneWeightVE   )
{
    // OSG_OGRE_LOG(("OgreMeshReader::readBoneAssignment\n");

    UInt32 vertIdx    = readUInt32(_is);
    UInt16 boneIdx    = readUInt16(_is);
    Real32 boneWeight = readReal32(_is);

    GeoVec4fPropertyUnrecPtr boneIdxProp;
    GeoVec4fPropertyUnrecPtr boneWeightProp;

    if(boneIdxVE < 0)
    {
        boneIdxProp = GeoVec4fProperty::create();

        VertexElement vElem;

        vElem.bufferIdx = 0;
        vElem.type      = VET_FLOAT4;
        vElem.semantic  = VES_BLEND_INDICES;
        vElem.offset    = 0;
        vElem.index     = 0;
        vElem.prop      = boneIdxProp;

        boneIdxVE       = UInt32(vertexElements.size());

        vertexElements.push_back(vElem);
    }

    if(boneWeightVE < 0)
    {
        boneWeightProp = GeoVec4fProperty::create();

        VertexElement vElem;

        vElem.bufferIdx = 0;
        vElem.type      = VET_FLOAT4;
        vElem.semantic  = VES_BLEND_WEIGHTS;
        vElem.offset    = 0;
        vElem.index     = 0;
        vElem.prop      = boneWeightProp;

        boneWeightVE    = UInt32(vertexElements.size());

        vertexElements.push_back(vElem);
    }

    boneIdxProp    = dynamic_pointer_cast<GeoVec4fProperty>(vertexElements[boneIdxVE   ].prop);
    boneWeightProp = dynamic_pointer_cast<GeoVec4fProperty>(vertexElements[boneWeightVE].prop);

    GeoVec4fProperty::StoredFieldType* boneIdxF    = boneIdxProp   ->editFieldPtr();
    GeoVec4fProperty::StoredFieldType* boneWeightF = boneWeightProp->editFieldPtr();

    if(vertIdx >= boneIdxF->size())
        boneIdxF->resize(vertIdx + 1, Vec4f(-1.f, -1.f, -1.f, -1.f));

    if(vertIdx >= boneWeightF->size())
        boneWeightF->resize(vertIdx + 1, Vec4f(0.f, 0.f, 0.f, 0.f));

    bool found = false;

    for(UInt16 i = 0; i < 4; ++i)
    {
        if((*boneIdxF)[vertIdx][i] < 0.f)
        {
            if((*boneIdxF)[vertIdx][i] != -1.f)
            {
                SINFO << "OgreMeshReader::readBoneAssignment: "
                      << "vertex '" << vertIdx
                      << "' has negative influence from ("
                      << (*boneIdxF   )[vertIdx][i] << ", "
                      << (*boneWeightF)[vertIdx][i]
                      << ")" << std::endl;
            }

            (*boneIdxF   )[vertIdx][i] = boneIdx;
            (*boneWeightF)[vertIdx][i] = boneWeight;

            found = true;
            break;
        }
        else if((*boneIdxF)[vertIdx][i] == boneIdx)
        {
            if((*boneWeightF)[vertIdx][i] < boneWeight)
            {
                OSG_OGRE_LOG(("OgreMeshReader::readBoneAssignment: "
                              "vertex '%u' changing bone influence from "
                              "(%f, %f) to (%f %f).\n",
                              vertIdx,
                              (*boneIdxF   )[vertIdx][i],
                              (*boneWeightF)[vertIdx][i],
                              boneIdx, boneWeight));

                (*boneWeightF)[vertIdx][i] = boneWeight;
            }
            else
            {
                OSG_OGRE_LOG(("OgreMeshReader::readBoneAssignment: "
                              "vertex '%u' already influenced by bone "
                              "(%u, %f) ignoring new weight %f.\n",
                              vertIdx, boneIdx,
                              (*boneWeightF)[vertIdx][i], boneWeight));
            }

            found = true;
            break;
        }
    }

    if(found == false)
    {
        SWARNING << "OgreMeshReader::readBoneAssignment: "
                 << "vertex '" << vertIdx
                 << "' has more than 4 bones assigned." << std::endl;

        UInt16 smallestWeightIdx = 0;
        Real32 smallestWeight    = TypeTraits<Real32>::getMax();

        for(UInt16 i = 0; i < 4; ++i)
        {
            if((*boneWeightF)[vertIdx][i] < smallestWeight)
            {
                smallestWeightIdx = i;
                smallestWeight    = (*boneWeightF)[vertIdx][i];
            }
        }

        if((*boneWeightF)[vertIdx][smallestWeightIdx] < boneWeight)
        {
            OSG_OGRE_LOG(("OgreMeshReader::readBoneAssignment: "
                          "vertex '%u' replacing smallest influence "
                          "(%f, %f) with (%f, %f).\n",
                          vertIdx,
                          (*boneIdxF   )[vertIdx][smallestWeightIdx],
                          (*boneWeightF)[vertIdx][smallestWeightIdx],
                          boneIdx, boneWeight));

            (*boneIdxF   )[vertIdx][smallestWeightIdx] = boneIdx;
            (*boneWeightF)[vertIdx][smallestWeightIdx] = boneWeight;
        }
        else
        {
            OSG_OGRE_LOG(("OgreMeshReader::readBoneAssignment: "
                          "vertex '%u' smallest existing influence "
                          "(%f, %f) is larger than (%f, %f).\n",
                          (*boneIdxF   )[vertIdx][smallestWeightIdx],
                          (*boneWeightF)[vertIdx][smallestWeightIdx],
                          boneIdx, boneWeight));
        }
    }
}
void
OgreMeshReader::readGeometryVertexBufferData(UInt32              vertCount,
                                             UInt16              bindIdx,
                                             VertexElementStore &vertexElements,
                                             BufferVertexMap    &bufferMap      )
{
    OSG_OGRE_LOG(("OgreMeshReader::readGeometryVertexBufferData\n"));

    for(UInt32 i = 0; i < vertCount; ++i)
    {
        for(UInt32 j = 0; j < bufferMap[bindIdx].size(); ++j)
        {
            UInt32 veIdx = bufferMap[bindIdx][j];

            switch(vertexElements[veIdx].type)
            {
            case VET_FLOAT1:
            {
                Vec1f v(readReal32(_is));
                vertexElements[veIdx].prop->addValue(v);
            }
            break;

            case VET_FLOAT2:
            {
                Vec2f v;
                v[0] = readReal32(_is);
                v[1] = readReal32(_is);

                vertexElements[veIdx].prop->addValue(v);
            }
            break;

            case VET_FLOAT3:
            {
                Vec3f v;
                v[0] = readReal32(_is);
                v[1] = readReal32(_is);
                v[2] = readReal32(_is);

                vertexElements[veIdx].prop->addValue(v);
            }
            break;

            case VET_FLOAT4:
            {
                Vec4f v;
                v[0] = readReal32(_is);
                v[1] = readReal32(_is);
                v[2] = readReal32(_is);
                v[3] = readReal32(_is);

                vertexElements[veIdx].prop->addValue(v);
            }
            break;

            case VET_COLOUR:
                break;

            case VET_SHORT1:
            {
                Vec1s v(readInt16(_is));
                vertexElements[veIdx].prop->addValue(v);
            }
            break;

            case VET_SHORT2:
            {
                Vec2s v;
                v[0] = readInt16(_is);
                v[1] = readInt16(_is);

                vertexElements[veIdx].prop->addValue(v);
            }
            break;

            case VET_SHORT3:
            {
                Vec3s v;
                v[0] = readInt16(_is);
                v[1] = readInt16(_is);
                v[2] = readInt16(_is);

                vertexElements[veIdx].prop->addValue(v);
            }
            break;

            case VET_SHORT4:
            {
                Vec4s v;
                v[0] = readInt16(_is);
                v[1] = readInt16(_is);
                v[2] = readInt16(_is);
                v[3] = readInt16(_is);

                vertexElements[veIdx].prop->addValue(v);
            }
            break;

            case VET_UBYTE4:
                readUInt32(_is);
                SWARNING << "OgreMeshReader::readGeometryVertexBufferData: "
                         << "type VET_UBYTE4 NIY" << std::endl;
                break;

            case VET_COLOUR_ARGB:
                SWARNING << "OgreMeshReader::readGeometryVertexBufferData: "
                         << "type VET_COLOUR_ARGB NIY" << std::endl;
                break;

            case VET_COLOUR_ABGR:
                SWARNING << "OgreMeshReader::readGeometryVertexBufferData: "
                         << "type VET_COLOUR_ABGR NIY" << std::endl;
                break;
            }
        }
    }
}
void
OgreMeshReader::readSubMesh(SubMeshStore       &subMeshInfo,
                            VertexElementStore &sharedVertexElements,
                            bool                skelAnim             )
{
    OSG_OGRE_LOG(("OgreMeshReader::readSubMesh\n"));

    subMeshInfo.push_back((SubMeshInfo()));
    SubMeshInfo &smInfo = subMeshInfo.back();

    smInfo.matName       = readString(_is);
    smInfo.sharedVertex  = readBool  (_is);
    UInt32      idxCount = readUInt32(_is);
    bool        idx32Bit = readBool  (_is);

    OSG_OGRE_LOG(("OgreMeshReader::readSubMesh: matName '%s' sharedVert '%d' "
                  "idxCount '%d' idx32Bit '%d'\n",
                  smInfo.matName.c_str(), smInfo.sharedVertex, idxCount, idx32Bit));

    smInfo.skelAnim = skelAnim;
    smInfo.meshOp   = SMO_TRIANGLE_LIST;

    if(idx32Bit == true)
    {
        GeoUInt32PropertyUnrecPtr pi = GeoUInt32Property::create();
        pi->resize(idxCount);

        _is.read(reinterpret_cast<Char8 *>(&pi->editField().front()),
                 idxCount * sizeof(UInt32));

        smInfo.propIdx = pi;
    }
    else
    {
        GeoUInt16PropertyUnrecPtr pi = GeoUInt16Property::create();
        pi->resize(idxCount);

        _is.read(reinterpret_cast<Char8 *>(&pi->editField().front()),
                 idxCount * sizeof(UInt16));

        smInfo.propIdx = pi;
    }

    Int16 boneIdxVE    = -1;
    Int16 boneWeightVE = -1;
    bool  stop         = false;

    while(_is)
    {
        readChunkHeader(_is);

        switch(_header.chunkId)
        {
        case CHUNK_GEOMETRY:
            readGeometry(smInfo.vertexElements);
            break;

        case CHUNK_SUBMESH_OPERATION:
            readSubMeshOperation(smInfo);
            break;

        case CHUNK_SUBMESH_BONE_ASSIGNMENT:
            readSubMeshBoneAssignment(smInfo, boneIdxVE, boneWeightVE);
            break;

        case CHUNK_SUBMESH_TEXTURE_ALIAS:
            readSubMeshTextureAlias();
            break;

        default:
            OSG_OGRE_LOG(("OgreMeshReader::readSubMesh: Unknown chunkId '0x%x'\n",
                          _header.chunkId));
            stop = true;
            break;
        };

        if(stop == true)
        {
            skip(_is, -_chunkHeaderSize);
            break;
        }
    }

    if(boneIdxVE >= 0 || boneWeightVE >= 0)
    {
        verifyBoneAssignment(smInfo.vertexElements, boneIdxVE, boneWeightVE);
    }
}
Exemplo n.º 23
0
bool convertWOFFToSfnt(SharedBuffer* woff, Vector<char>& sfnt)
{
    ASSERT_ARG(sfnt, sfnt.isEmpty());

    size_t offset = 0;

    // Read the WOFF header.
    uint32_t signature;
    if (!readUInt32(woff, offset, signature) || signature != woffSignature) {
        ASSERT_NOT_REACHED();
        return false;
    }

    uint32_t flavor;
    if (!readUInt32(woff, offset, flavor))
        return false;

    uint32_t length;
    if (!readUInt32(woff, offset, length) || length != woff->size())
        return false;

    uint16_t numTables;
    if (!readUInt16(woff, offset, numTables))
        return false;

    if (!numTables || numTables > 0x0fff)
        return false;

    uint16_t reserved;
    if (!readUInt16(woff, offset, reserved) || reserved)
        return false;

    uint32_t totalSfntSize;
    if (!readUInt32(woff, offset, totalSfntSize))
        return false;

    if (woff->size() - offset < sizeof(uint16_t) + sizeof(uint16_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t) + sizeof(uint32_t))
        return false;

    offset += sizeof(uint16_t); // majorVersion
    offset += sizeof(uint16_t); // minorVersion
    offset += sizeof(uint32_t); // metaOffset
    offset += sizeof(uint32_t); // metaLength
    offset += sizeof(uint32_t); // metaOrigLength
    offset += sizeof(uint32_t); // privOffset
    offset += sizeof(uint32_t); // privLength

    // Check if the WOFF can supply as many tables as it claims it has.
    if (woff->size() - offset < numTables * 5 * sizeof(uint32_t))
        return false;

    // Write the sfnt offset subtable.
    uint16_t entrySelector = 0;
    uint16_t searchRange = 1;
    while (searchRange < numTables >> 1) {
        entrySelector++;
        searchRange <<= 1;
    }
    searchRange <<= 4;
    uint16_t rangeShift = (numTables << 4) - searchRange;

    if (!writeUInt32(sfnt, flavor)
        || !writeUInt16(sfnt, numTables)
        || !writeUInt16(sfnt, searchRange)
        || !writeUInt16(sfnt, entrySelector)
        || !writeUInt16(sfnt, rangeShift))
        return false;

    if (sfnt.size() > totalSfntSize)
        return false;

    if (totalSfntSize - sfnt.size() < numTables * 4 * sizeof(uint32_t))
        return false;

    size_t sfntTableDirectoryCursor = sfnt.size();
    sfnt.grow(sfnt.size() + numTables * 4 * sizeof(uint32_t));

    // Process tables.
    for (uint16_t i = 0; i < numTables; ++i) {
        // Read a WOFF table directory entry.
        uint32_t tableTag;
        if (!readUInt32(woff, offset, tableTag))
            return false;

        uint32_t tableOffset;
        if (!readUInt32(woff, offset, tableOffset))
            return false;

        uint32_t tableCompLength;
        if (!readUInt32(woff, offset, tableCompLength))
            return false;

        if (tableOffset > woff->size() || tableCompLength > woff->size() - tableOffset)
            return false;

        uint32_t tableOrigLength;
        if (!readUInt32(woff, offset, tableOrigLength) || tableCompLength > tableOrigLength)
            return false;

        if (tableOrigLength > totalSfntSize || sfnt.size() > totalSfntSize - tableOrigLength)
            return false;

        uint32_t tableOrigChecksum;
        if (!readUInt32(woff, offset, tableOrigChecksum))
            return false;

        // Write an sfnt table directory entry.
        uint32_t* sfntTableDirectoryPtr = reinterpret_cast<uint32_t*>(sfnt.data() + sfntTableDirectoryCursor);
        *sfntTableDirectoryPtr++ = htonl(tableTag);
        *sfntTableDirectoryPtr++ = htonl(tableOrigChecksum);
        *sfntTableDirectoryPtr++ = htonl(sfnt.size());
        *sfntTableDirectoryPtr++ = htonl(tableOrigLength);
        sfntTableDirectoryCursor += 4 * sizeof(uint32_t);

        if (tableCompLength == tableOrigLength) {
            // The table is not compressed.
            if (!sfnt.tryAppend(woff->data() + tableOffset, tableCompLength))
                return false;
        } else {
            uLongf destLen = tableOrigLength;
            if (!sfnt.tryReserveCapacity(sfnt.size() + tableOrigLength))
                return false;
            Bytef* dest = reinterpret_cast<Bytef*>(sfnt.end());
            sfnt.grow(sfnt.size() + tableOrigLength);
            if (uncompress(dest, &destLen, reinterpret_cast<const Bytef*>(woff->data() + tableOffset), tableCompLength) != Z_OK)
                return false;
            if (destLen != tableOrigLength)
                return false;
        }

        // Pad to a multiple of 4 bytes.
        while (sfnt.size() % 4)
            sfnt.append(0);
    }

    return sfnt.size() == totalSfntSize;
}
Exemplo n.º 24
0
STDMETHODIMP_(void) CCMIAdapter::setUInt32Bit(UInt8 reg, UInt32 flag)
{
	writeUInt32(reg, readUInt32(reg) | flag);
}
Exemplo n.º 25
0
void MapFileSerializer::importMapFile( Ogre::DataStreamPtr& stream, WorldMapFile& dest )
{
    const auto fileSize = stream->size();
    auto numBlocks = fileSize / kWorldMapBlockSize;

    for ( unsigned int j=0; j<numBlocks; j++ )
    {

        SBlock block;

        const size_t basePos = kWorldMapBlockSize*j;
        stream->seek( basePos );

        // Read the offset to compressed data in this block
        BlockHeader header = {};
        for ( auto i=0u; i<16; i++)
        {
            readUInt32( stream, header.mCompressedDataOffsets[i] );
        }

        for ( auto i=0u; i<16; i++)
        {
            SBlockPart blockPart;

            // Go to the offset
            stream->seek( basePos + header.mCompressedDataOffsets[i] );

            // Read the size of the compressed data
            uint32 compressedDataSize = 0;
            readUInt32( stream, compressedDataSize );

            // Go back to before the compressed data size
            stream->seek( basePos + header.mCompressedDataOffsets[i] );

            // Read the compressed data into a temp buffer, including the compressed data size
            std::vector<uint8> buffer( compressedDataSize + 4 );
            stream->read(buffer.data(), buffer.size());

            // Decompress the data
            auto decompressed = LzsBuffer::Decompress(buffer);

            Ogre::MemoryDataStream decStream(decompressed.data(), decompressed.size(), false, true);

            readUInt16(decStream, blockPart.mHeader.NumberOfTriangles);
            readUInt16(decStream, blockPart.mHeader.NumberOfVertices);

            /*
            std::cout << "block: " << j
                      << " from offset " << header.mCompressedDataOffsets[i]
                      << " old size: " << buffer.size()
                      << " decompressed size is " << decompressed.size()
                      << " header is tris: " <<  blockPart.mHeader.NumberOfTriangles
                      << " verts " << blockPart.mHeader.NumberOfVertices
                      << std::endl;*/


            blockPart.mTris.resize(blockPart.mHeader.NumberOfTriangles);
            for ( int k=0; k<blockPart.mHeader.NumberOfTriangles; k++)
            {
                BlockTriangle& s = blockPart.mTris[k];

                readUInt8( decStream, s.Vertex0Index );
                readUInt8( decStream, s.Vertex1Index );
                readUInt8( decStream, s.Vertex2Index );

                readUInt8( decStream, s.WalkabilityInfo );
                //readUInt8( decStream, s.Unknown );

                readUInt8( decStream, s.uVertex0 );
                readUInt8( decStream, s.vVertex0 );

                readUInt8( decStream, s.uVertex1 );
                readUInt8( decStream, s.vVertex1 );

                readUInt8( decStream, s.uVertex2 );
                readUInt8( decStream, s.vVertex2 );

                readUInt16( decStream, s.TextureInfo );

                s.TextureInfo = s.TextureInfo & 0x1FF;

                //readUInt16( decStream, s.Location );

                /*
                std::cout << "v0: " << int(s.Vertex0Index)
                          << " v1 " << int(s.Vertex1Index)
                          << " v2 " << int(s.Vertex2Index)
                          << " walk " << int(s.WalkabilityInfo)
                          << " u1 " << int(s.uVertex1)
                          << " v1 " << int(s.vVertex1)
                          << " v2 " << int(s.uVertex2)
                          << " u2 " << int(s.vVertex2)
                          << " texture " << s.TextureInfo
                          << " locId " << s.Location
                          << std::endl;*/

            }

            blockPart.mNormal.resize( blockPart.mHeader.NumberOfVertices );
            blockPart.mVertices.resize( blockPart.mHeader.NumberOfVertices );

            // All verts
            for ( int k=0; k<blockPart.mHeader.NumberOfVertices; k++)
            {
                Vertex& v = blockPart.mVertices[k];
                readInt16( decStream, v.X );
                readInt16( decStream, v.Y );
                readInt16( decStream, v.Z );
                readUInt16( decStream, v.Unused );
            }

            // Then all normals
            for ( int k=0; k<blockPart.mHeader.NumberOfVertices; k++)
            {
                Normal& n = blockPart.mNormal[k];
                readInt16( decStream, n.X );
                readInt16( decStream, n.Y );
                readInt16( decStream, n.Z );
                readUInt16( decStream, n.Unused );
            }

            block.mMeshes.push_back( blockPart );
        }
        mBlocks.push_back(block);
    }
}
Exemplo n.º 26
0
STDMETHODIMP_(void) CCMIAdapter::clearUInt32Bit(UInt8 reg, UInt32 flag)
{
	writeUInt32(reg, readUInt32(reg) & ~flag);
}
Exemplo n.º 27
0
    bool Language::initFromFile(const std::string& filename)
    {
        const unsigned long MAGIC_BIG = 0xde120495;
        const unsigned long MAGIC_LITTLE = 0x950412de;

        std::vector<uint8_t> data;

        if (!sharedEngine->getFileSystem()->loadFile(filename, data))
        {
            return false;
        }

        uint32_t offset = 0;

        if (data.size() < 5 * sizeof(uint32_t))
        {
            return false;
        }

        uint32_t magic = *reinterpret_cast<uint32_t*>(data.data() + offset);
        offset += sizeof(magic);

        uint32_t (*readUInt32)(const uint8_t*) = nullptr;

        if (magic == MAGIC_BIG)
        {
            readUInt32 = readUInt32Big;
        }
        else if (magic == MAGIC_LITTLE)
        {
            readUInt32 = readUInt32Little;
        }
        else
        {
            log("Wrong magic %x", magic);
            return false;
        }

        uint32_t revision = readUInt32(data.data() + offset);
        offset += sizeof(revision);

        if (revision != 0)
        {
            log("Unsupported revision %d", revision);
            return false;
        }

        uint32_t stringCount = readUInt32(data.data() + offset);
        offset += sizeof(stringCount);

        std::vector<TranslationInfo> translations(stringCount);

        uint32_t stringsOffset = readUInt32(data.data() + offset);
        offset += sizeof(stringsOffset);

        uint32_t translationsOffset = readUInt32(data.data() + offset);
        offset += sizeof(translationsOffset);

        offset = stringsOffset;

        if (data.size() < offset + 2 * sizeof(uint32_t) * stringCount)
        {
            return false;
        }

        for (uint32_t i = 0; i < stringCount; ++i)
        {
            translations[i].stringLength = readUInt32(data.data() + offset);
            offset += sizeof(translations[i].stringLength);

            translations[i].stringOffset = readUInt32(data.data() + offset);
            offset += sizeof(translations[i].stringOffset);
        }

        offset = translationsOffset;

        if (data.size() < offset + 2 * sizeof(uint32_t) * stringCount)
        {
            return false;
        }

        for (uint32_t i = 0; i < stringCount; ++i)
        {
            translations[i].translationLength = readUInt32(data.data() + offset);
            offset += sizeof(translations[i].translationLength);

            translations[i].translationOffset = readUInt32(data.data() + offset);
            offset += sizeof(translations[i].translationOffset);
        }

        for (uint32_t i = 0; i < stringCount; ++i)
        {
            if (data.size() < translations[i].stringOffset + translations[i].stringLength ||
                data.size() < translations[i].translationOffset + translations[i].translationLength)
            {
                return false;
            }

            std::string str(reinterpret_cast<char*>(data.data() + translations[i].stringOffset), translations[i].stringLength);
            std::string translation(reinterpret_cast<char*>(data.data() + translations[i].translationOffset), translations[i].translationLength);

            strings[str] = translation;
        }

        return true;
    }
Exemplo n.º 28
0
INT32 DataInputStream::readInt32()
{
  return (INT32)readUInt32();
}
Exemplo n.º 29
0
std::string BinaryInput::readString32() {
    int len = readUInt32();
    return readString(len);
}
Exemplo n.º 30
0
int GameState::readInt32(int32_t* pInt32) {
	return readUInt32((uint32_t*)pInt32);
}