public void Read(Stream inputStream, bool absoluteOffset, bool flipEndian = false) { X360Reader reader = new X360Reader(inputStream, Encoding.Default, true, flipEndian); ushort compressedChunkSize = reader.ReadUInt16(); ushort decompressedChunkSize = reader.ReadUInt16(); Offset = reader.ReadUInt32(); long indexEndPosition = reader.BaseStream.Position; if (absoluteOffset) { reader.BaseStream.Position = Offset; } else { // HACK: result.Offset could be 0x80000008 reader.BaseStream.Position = indexEndPosition + (Offset & OffsetBitMask) - IndexSize; } byte[] data = reader.ReadBytes(compressedChunkSize); bool dataCompressed = compressedChunkSize != decompressedChunkSize; SetData(data, dataCompressed, decompressedChunkSize); reader.BaseStream.Position = indexEndPosition; }
private void Read(Stream inputStream) { X360Reader reader = new X360Reader(inputStream, Encoding.Default, true, false); uint magicNumber = reader.ReadUInt32(); FlipEndian = magicNumber == 0x46544558; reader.BaseStream.Position -= 4; reader.FlipEndian = FlipEndian; magicNumber = reader.ReadUInt32(); if (magicNumber != MagicNumber1) return; magicNumber = reader.ReadUInt32(); if (magicNumber != MagicNumber2) return; PixelFormatType = reader.ReadInt16(); Width = reader.ReadInt16(); Height = reader.ReadInt16(); Depth = reader.ReadInt16(); MipMapCount = reader.ReadByte(); NrtFlag = reader.ReadByte(); UnknownFlags = reader.ReadInt16(); reader.FlipEndian = false; if (reader.ReadInt32() != OneInt32) return; if (reader.ReadInt32() != ZeroInt32) return; TextureType = (FtexTextureType) reader.ReadInt32(); FtexsFileCount = reader.ReadByte(); AdditionalFtexsFileCount = reader.ReadByte(); if (reader.ReadInt16() != 0) return; if (reader.ReadInt32() != ZeroInt32) return; if (reader.ReadInt32() != ZeroInt32) return; if (reader.ReadInt32() != ZeroInt32) return; Hash = reader.ReadBytes(16); reader.FlipEndian = FlipEndian; for (int i = 0; i < MipMapCount; i++) { FtexFileMipMapInfo fileMipMapInfo = FtexFileMipMapInfo.ReadFtexFileMipMapInfo(reader); AddMipMapInfo(fileMipMapInfo); } }