Example #1
0
        bool IsWsaD2(Stream s)
        {
            if (s.Length < 10)
                return false;

            var start = s.Position;

            numTiles = s.ReadUInt16();
            tileWidth = s.ReadUInt16();
            tileHeight = s.ReadUInt16();
            Delta = s.ReadUInt32();

            offsets = new uint[numTiles + 1];
            for (var i = 0; i <= numTiles; i++)
                offsets[i] = s.ReadUInt32();

            s.Position = start;

            //if (offsets[numTiles] < s.Length)
            //	return false;

            if (offsets[0] == 0)
            {
                numTiles -= 1;
                for (var i = 1; i <= numTiles; i++)
                    offsets[i - 1] = offsets[i];
            }

            return true;
        }
Example #2
0
		public D2kSoundResources(string filename, int priority)
		{
			this.filename = filename;
			this.priority = priority;

			s = GlobalFileSystem.Open(filename);
			try
			{
				filenames = new List<string>();

				var headerLength = s.ReadUInt32();
				while (s.Position < headerLength + 4)
				{
					var name = s.ReadASCIIZ();
					var offset = s.ReadUInt32();
					var length = s.ReadUInt32();

					var hash = PackageEntry.HashFilename(name, PackageHashType.Classic);
					if (!index.ContainsKey(hash))
						index.Add(hash, new PackageEntry(hash, offset, length));

					filenames.Add(name);
				}
			}
			catch
			{
				Dispose();
				throw;
			}
		}
Example #3
0
        public HvaReader(Stream s)
        {
            // Index swaps for transposing a matrix
            var ids = new byte[]{0,4,8,12,1,5,9,13,2,6,10,14};

            s.Seek(16, SeekOrigin.Begin);
            FrameCount = s.ReadUInt32();
            LimbCount = s.ReadUInt32();

            // Skip limb names
            s.Seek(16*LimbCount, SeekOrigin.Current);
            Transforms = new float[16*FrameCount*LimbCount];
            for (var j = 0; j < FrameCount; j++)
                for (var i = 0; i < LimbCount; i++)
            {
                // Convert to column-major matrices and add the final matrix row
                var c = 16*(LimbCount*j + i);
                Transforms[c + 3] = 0;
                Transforms[c + 7] = 0;
                Transforms[c + 11] = 0;
                Transforms[c + 15] = 1;

                for (var k = 0; k < 12; k++)
                    Transforms[c + ids[k]] = s.ReadFloat();
            }
        }
Example #4
0
		public PakFile(string filename, int priority)
		{
			this.filename = filename;
			this.priority = priority;
			index = new Dictionary<string, Entry>();

			stream = GlobalFileSystem.Open(filename);
			try
			{
				index = new Dictionary<string, Entry>();
				var offset = stream.ReadUInt32();
				while (offset != 0)
				{
					var file = stream.ReadASCIIZ();
					var next = stream.ReadUInt32();
					var length = (next == 0 ? (uint)stream.Length : next) - offset;

					// Ignore duplicate files
					if (index.ContainsKey(file))
						continue;

					index.Add(file, new Entry { Offset = offset, Length = length, Filename = file });
					offset = next;
				}
			}
			catch
			{
				Dispose();
				throw;
			}
		}
        public static IPackfile FromStream(Stream stream, bool isStr2)
        {
            stream.Seek(0, SeekOrigin.Begin);
            uint descriptor = stream.ReadUInt32();

            if (descriptor != 0x51890ACE)
                throw new Exception("The input is not a packfile!");

            uint version = stream.ReadUInt32();

            switch (version)
            {
                case 0x04: // Saints Row 2
                    return new Packfiles.Version04.Packfile(stream);

                case 0x06: // Saints Row: The Third
                    return new Packfiles.Version06.Packfile(stream, isStr2);

                case 0x0A: // Saints Row IV & Saints Row: Gat out of Hell
                    return new Packfiles.Version0A.Packfile(stream, isStr2);

                default:
                    throw new Exception(String.Format("Unsupported packfile version: {0:X4}", version));
            }
        }
Example #6
0
        public BigFile(FileSystem context, string filename)
        {
            Name = filename;

            s = context.Open(filename);
            try
            {
                if (s.ReadASCII(4) != "BIGF")
                    throw new InvalidDataException("Header is not BIGF");

                // Total archive size.
                s.ReadUInt32();

                var entryCount = s.ReadUInt32();
                if (BitConverter.IsLittleEndian)
                    entryCount = int2.Swap(entryCount);

                // First entry offset? This is apparently bogus for EA's .big files
                // and we don't have to try seeking there since the entries typically start next in EA's .big files.
                s.ReadUInt32();

                for (var i = 0; i < entryCount; i++)
                {
                    var entry = new Entry(s);
                    index.Add(entry.Path, entry);
                }
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Example #7
0
		public HvaReader(Stream s, string fileName)
		{
			// Index swaps for transposing a matrix
			var ids = new byte[] { 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14 };

			s.Seek(16, SeekOrigin.Begin);
			FrameCount = s.ReadUInt32();
			LimbCount = s.ReadUInt32();

			// Skip limb names
			s.Seek(16 * LimbCount, SeekOrigin.Current);
			Transforms = new float[16 * FrameCount * LimbCount];

			var testMatrix = new float[16];
			for (var j = 0; j < FrameCount; j++)
				for (var i = 0; i < LimbCount; i++)
				{
					// Convert to column-major matrices and add the final matrix row
					var c = 16 * (LimbCount * j + i);
					Transforms[c + 3] = 0;
					Transforms[c + 7] = 0;
					Transforms[c + 11] = 0;
					Transforms[c + 15] = 1;

					for (var k = 0; k < 12; k++)
						Transforms[c + ids[k]] = s.ReadFloat();

					Array.Copy(Transforms, 16 * (LimbCount * j + i), testMatrix, 0, 16);
					if (Util.MatrixInverse(testMatrix) == null)
						throw new InvalidDataException(
							"The transformation matrix for HVA file `{0}` section {1} frame {2} is invalid because it is not invertible!"
							.F(fileName, i, j));
				}
		}
Example #8
0
        private bool LoadFile( Stream stream )
        {
            string magic = stream.ReadAscii( 8 );
            uint strategySetCount = stream.ReadUInt32().SwapEndian();
            uint strategyOptionCount = stream.ReadUInt32().SwapEndian();
            uint refStringStart = stream.ReadUInt32().SwapEndian();

            StrategySetList = new List<StrategySet>( (int)strategySetCount );
            for ( uint i = 0; i < strategySetCount; ++i ) {
                StrategySet ss = new StrategySet( stream, refStringStart );
                StrategySetList.Add( ss );
            }
            StrategyOptionList = new List<StrategyOption>( (int)strategyOptionCount );
            for ( uint i = 0; i < strategyOptionCount; ++i ) {
                StrategyOption so = new StrategyOption( stream, refStringStart );
                StrategyOptionList.Add( so );
            }

            StrategyOptionDict = new Dictionary<uint, StrategyOption>( StrategyOptionList.Count );
            foreach ( var option in StrategyOptionList ) {
                StrategyOptionDict.Add( option.InGameID, option );
            }

            return true;
        }
        public WwiseSoundbank(Stream s)
        {
            while (s.Position < s.Length)
            {
                SectionId sectionId = (SectionId)s.ReadUInt32();
                uint length = s.ReadUInt32();
                byte[] data = new byte[length];
                s.Read(data, 0, (int)length);

                switch (sectionId)
                {
                    case SectionId.BKHD:
                        BKHDSection bkhd = new BKHDSection(data);
                        Sections.Add(bkhd);
                        break;
                    case SectionId.ENVS:
                        ENVSSection envs = new ENVSSection(data);
                        Sections.Add(envs);
                        break;
                    case SectionId.HIRC:
                        HIRCSection hirc = new HIRCSection(data);
                        Sections.Add(hirc);
                        break;
                    case SectionId.STMG:
                        STMGSection stmg = new STMGSection(data);
                        Sections.Add(stmg);
                        break;
                    default:
                        throw new NotImplementedException("Unknown section: " + sectionId.ToString());
                }
            }
        }
Example #10
0
        /// <summary>
        /// インスタンスを初期化します。
        /// </summary>
        /// <param name="src">オブジェクト情報を読み取るストリーム。位置はオブジェクトのボディ先頭 ( サイズ情報の直後 ) に設定します。新規作成なら null を指定します。</param>
        public FilePropertiesObject( Stream src )
        {
            if( src == null )
            {
                this.FileId   = Guid.NewGuid();
                this.FileSize = ( ulong )this.Size;
            }
            else
            {
                this.FileId           = src.ReadGuid();
                this.FileSize         = src.ReadUInt64();
                this.CreationDate     = DateTime.FromFileTimeUtc( ( long )src.ReadUInt64() );
                this.DataPacketsCount = src.ReadUInt64();
                this.Duration         = src.ReadUInt64();
                this.SendDuration     = TimeSpan.FromTicks( ( long )src.ReadUInt64() );
                this.Preroll          = src.ReadUInt64();

                // 再生時間から Preroll x 10000 を差し引いたものが、実際の演奏時間となる。
                // この値は複数値からの算出が必要なので、遅延読み込みせずにキャッシュする。
                //
                this.Duration -= ( this.Preroll * FilePropertiesObject.PrerollDelta );

                this.Flags                 = src.ReadUInt32();
                this.MinimumDataPacketSize = src.ReadUInt32();
                this.MaximumDataPacketSize = src.ReadUInt32();
                this.MaximumBitrate        = src.ReadUInt32();
            }
        }
			public FileGroup(Stream reader, long offset)
			{
				var nameOffset = reader.ReadUInt32();
				/*   unknown  */ reader.ReadBytes(18);
				FirstFile = reader.ReadUInt32();
				LastFile = reader.ReadUInt32();

				reader.Seek(offset + (long)nameOffset, SeekOrigin.Begin);
				Name = reader.ReadASCIIZ();
			}
Example #12
0
        private bool LoadFile( Stream stream, uint textPointerLocationDiff )
        {
            string magic = stream.ReadAscii( 8 );
            uint alwaysSame = stream.ReadUInt32().SwapEndian();
            uint filesize = stream.ReadUInt32().SwapEndian();

            uint lengthSection1 = stream.ReadUInt32().SwapEndian();

            stream.Position = 0x50;
            int textPointerDiffDiff = (int)stream.ReadUInt32().SwapEndian();
            stream.Position = 0x20;
            uint textStart = stream.ReadUInt32().SwapEndian();
            int textPointerDiff = (int)stream.ReadUInt32().SwapEndian() - textPointerDiffDiff;

            EntryList = new List<ScenarioFileEntry>();

            // i wonder what the actual logic behind this is...
            uint textPointersLocation = ( lengthSection1 + 0x80 ).Align( 0x10 ) + textPointerLocationDiff;
            // + 0x1888; // + 0x1B4C // diff of 2C4 // Actually this isn't constant, dammit.

            if ( textStart != textPointersLocation ) {
                stream.Position = textPointersLocation;

                while ( true ) {
                    long loc = stream.Position;
                    stream.DiscardBytes( 8 );
                    uint[] ptrs = new uint[4];
                    ptrs[0] = stream.ReadUInt32().SwapEndian();
                    ptrs[1] = stream.ReadUInt32().SwapEndian();
                    ptrs[2] = stream.ReadUInt32().SwapEndian();
                    ptrs[3] = stream.ReadUInt32().SwapEndian();

                    if ( stream.Position > textStart ) { break; }
                    if ( ptrs.Any( x => x == 0 ) ) { break; }
                    if ( ptrs.Any( x => x + textPointerDiff < textStart ) ) { break; }
                    if ( ptrs.Any( x => x + textPointerDiff >= filesize ) ) { break; }

                    var s = new ScenarioFileEntry();
                    s.Pointer = (uint)loc;
                    stream.Position = ptrs[0] + textPointerDiff;
                    s.JpName = stream.ReadShiftJisNullterm();
                    stream.Position = ptrs[1] + textPointerDiff;
                    s.JpText = stream.ReadShiftJisNullterm();
                    stream.Position = ptrs[2] + textPointerDiff;
                    s.EnName = stream.ReadShiftJisNullterm();
                    stream.Position = ptrs[3] + textPointerDiff;
                    s.EnText = stream.ReadShiftJisNullterm();
                    EntryList.Add( s );

                    stream.Position = loc + 0x18;
                }
            }

            return true;
        }
Example #13
0
        bool IsTmpTD(Stream s)
        {
            var start = s.Position;

            s.Position += 16;
            var a = s.ReadUInt32();
            var b = s.ReadUInt32();

            s.Position = start;
            return a == 0 && b == 0x0D1AFFFF;
        }
        public InstallShieldCABExtractor(FileSystem context, string hdrFilename)
        {
            var fileGroups = new List<FileGroup>();
            var fileGroupOffsets = new List<uint>();

            hdrFile = context.Open(hdrFilename);
            this.context = context;

            // Strips archive number AND file extension
            Name = Regex.Replace(hdrFilename, @"\d*\.[^\.]*$", "");
            var signature = hdrFile.ReadUInt32();

            if (signature != 0x28635349)
                throw new InvalidDataException("Not an Installshield CAB package");

            commonHeader = new CommonHeader(hdrFile);
            cabDescriptor = new CabDescriptor(hdrFile, commonHeader);
            /*    unknown   */ hdrFile.ReadBytes(14);

            for (var i = 0U; i < MaxFileGroupCount; ++i)
                fileGroupOffsets.Add(hdrFile.ReadUInt32());

            hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset, SeekOrigin.Begin);
            directoryTable = new List<uint>();

            for (var i = 0U; i < cabDescriptor.DirectoryCount; ++i)
                directoryTable.Add(hdrFile.ReadUInt32());

            foreach (var offset in fileGroupOffsets)
            {
                var nextOffset = offset;
                while (nextOffset != 0)
                {
                    hdrFile.Seek((long)nextOffset + 4 + commonHeader.CabDescriptorOffset, SeekOrigin.Begin);
                    var descriptorOffset = hdrFile.ReadUInt32();
                    nextOffset = hdrFile.ReadUInt32();
                    hdrFile.Seek(descriptorOffset + commonHeader.CabDescriptorOffset, SeekOrigin.Begin);

                    fileGroups.Add(new FileGroup(hdrFile, commonHeader.CabDescriptorOffset));
                }
            }

            hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset + cabDescriptor.FileTableOffset2, SeekOrigin.Begin);
            foreach (var fileGroup in fileGroups)
            {
                for (var i = fileGroup.FirstFile; i <= fileGroup.LastFile; ++i)
                {
                    AddFileDescriptorToList(i);
                    var fileDescriptor = fileDescriptors[i];
                    var fullFilePath   = "{0}\\{1}\\{2}".F(fileGroup.Name, DirectoryName(fileDescriptor.DirectoryIndex), fileDescriptor.Filename);
                    index.Add(fullFilePath, i);
                }
            }
        }
Example #15
0
        private bool LoadFile( Stream stream )
        {
            string magic = stream.ReadAscii( 8 );
            uint blockCount = stream.ReadUInt32().SwapEndian();
            uint refStringStart = stream.ReadUInt32().SwapEndian();

            Blocks = new List<T8BTVABlock>( (int)blockCount );
            for ( uint i = 0; i < blockCount; ++i ) {
                Blocks.Add( new T8BTVABlock( stream, refStringStart ) );
            }

            return true;
        }
Example #16
0
        private bool LoadFile( Stream stream )
        {
            string magic = stream.ReadAscii( 8 );
            uint entryCount = stream.ReadUInt32().SwapEndian();
            uint refStringStart = stream.ReadUInt32().SwapEndian();

            GradeShopEntryList = new List<GradeShopEntry>( (int)entryCount );
            for ( uint i = 0; i < entryCount; ++i ) {
                GradeShopEntry e = new GradeShopEntry( stream, refStringStart );
                GradeShopEntryList.Add( e );
            }

            return true;
        }
Example #17
0
        private bool LoadFile( Stream stream )
        {
            string magic = stream.ReadAscii( 8 );
            uint floorInfoCount = stream.ReadUInt32().SwapEndian();
            uint refStringStart = stream.ReadUInt32().SwapEndian();

            FloorList = new List<FloorInfo>( (int)floorInfoCount );
            for ( uint i = 0; i < floorInfoCount; ++i ) {
                FloorInfo fi = new FloorInfo( stream, refStringStart );
                FloorList.Add( fi );
            }

            return true;
        }
Example #18
0
        private bool LoadFile( Stream stream )
        {
            string magic = stream.ReadAscii( 8 );
            uint unknown = stream.ReadUInt32().SwapEndian();
            uint titleCount = stream.ReadUInt32().SwapEndian();

            TitleList = new List<Title>( (int)titleCount );
            for ( uint i = 0; i < titleCount; ++i ) {
                Title t = new Title( stream );
                TitleList.Add( t );
            }

            return true;
        }
Example #19
0
        private bool LoadFile( Stream stream )
        {
            string magic = stream.ReadAscii( 8 );
            uint infoCount = stream.ReadUInt32().SwapEndian();
            uint refStringStart = stream.ReadUInt32().SwapEndian();

            TreasureInfoList = new List<TreasureInfo>( (int)infoCount );
            for ( uint i = 0; i < infoCount; ++i ) {
                TreasureInfo ti = new TreasureInfo( stream, refStringStart );
                TreasureInfoList.Add( ti );
            }

            return true;
        }
        private static List<ScenarioFileEntry> FindText( Stream stream, uint textStart, bool isUtf8 )
        {
            var list = new List<ScenarioFileEntry>();

            while ( stream.Position < textStart ) {
                uint identifyingBytes = stream.ReadUInt32();
                if ( identifyingBytes == 0x18000C04 ) {
                    uint pos = (uint)stream.Position;

                    uint pointerToText = stream.ReadUInt32().SwapEndian() + textStart;

                    stream.Position = pointerToText;
                    stream.ReadUInt32().SwapEndian();
                    stream.ReadUInt32().SwapEndian();
                    uint jpNamePtr = stream.ReadUInt32().SwapEndian();
                    uint jpTextPtr = stream.ReadUInt32().SwapEndian();
                    uint enNamePtr = stream.ReadUInt32().SwapEndian();
                    uint enTextPtr = stream.ReadUInt32().SwapEndian();
                    stream.Position = jpNamePtr + textStart; string jpName = isUtf8 ? stream.ReadUTF8Nullterm() : stream.ReadShiftJisNullterm();
                    stream.Position = jpTextPtr + textStart; string jpText = isUtf8 ? stream.ReadUTF8Nullterm() : stream.ReadShiftJisNullterm();
                    stream.Position = enNamePtr + textStart; string enName = isUtf8 ? stream.ReadUTF8Nullterm() : stream.ReadShiftJisNullterm();
                    stream.Position = enTextPtr + textStart; string enText = isUtf8 ? stream.ReadUTF8Nullterm() : stream.ReadShiftJisNullterm();

                    var entry = new ScenarioFileEntry() { Pointer = pos, JpName = jpName, EnName = enName, JpText = jpText, EnText = enText };
                    list.Add( entry );

                    stream.Position = pos + 4;
                }
            }

            return list;
        }
Example #21
0
        private bool LoadFile( Stream stream )
        {
            string magic = stream.ReadAscii( 8 );
            uint unknown = stream.ReadUInt32().SwapEndian();
            uint recipeCount = stream.ReadUInt32().SwapEndian();

            RecipeList = new List<Recipe>( (int)recipeCount );
            for ( uint i = 0; i < recipeCount; ++i ) {
                Recipe r = new Recipe( stream );
                RecipeList.Add( r );
            }

            return true;
        }
Example #22
0
        public InstallShieldPackage(FileSystem context, string filename)
        {
            Name = filename;

            s = context.Open(filename);
            try
            {
                // Parse package header
                var signature = s.ReadUInt32();
                if (signature != 0x8C655D13)
                    throw new InvalidDataException("Not an Installshield package");

                s.Position += 8;
                /*var FileCount = */s.ReadUInt16();
                s.Position += 4;
                /*var ArchiveSize = */s.ReadUInt32();
                s.Position += 19;
                var tocAddress = s.ReadInt32();
                s.Position += 4;
                var dirCount = s.ReadUInt16();

                // Parse the directory list
                s.Position = tocAddress;

                // Parse directories
                var directories = new Dictionary<string, uint>();
                for (var i = 0; i < dirCount; i++)
                {
                    // Parse directory header
                    var fileCount = s.ReadUInt16();
                    var chunkSize = s.ReadUInt16();
                    var nameLength = s.ReadUInt16();
                    var dirName = s.ReadASCII(nameLength);

                    // Skip to the end of the chunk
                    s.ReadBytes(chunkSize - nameLength - 6);
                    directories.Add(dirName, fileCount);
                }

                // Parse files
                foreach (var dir in directories)
                    for (var i = 0; i < dir.Value; i++)
                        ParseFile(s, dir.Key);
            }
            catch
            {
                Dispose();
                throw;
            }
        }
Example #23
0
			public Entry(Stream s)
			{
				this.s = s;

				offset = s.ReadUInt32();
				size = s.ReadUInt32();
				if (BitConverter.IsLittleEndian)
				{
					offset = int2.Swap(offset);
					size = int2.Swap(size);
				}

				Path = s.ReadASCIIZ();
			}
        public InstallShieldCABCompression(Stream header, Dictionary<int, Stream> volumes)
        {
            this.volumes = volumes;

            if (header.ReadUInt32() != 0x28635349)
                throw new InvalidDataException("Not an Installshield CAB package");

            header.Position += 8;
            var cabDescriptorOffset = header.ReadUInt32();
            header.Position = cabDescriptorOffset + 12;
            var cabDescriptor = new CabDescriptor(header);
            header.Position += 14;

            var fileGroupOffsets = new uint[MaxFileGroupCount];
            for (var i = 0; i < MaxFileGroupCount; i++)
                fileGroupOffsets[i] = header.ReadUInt32();

            header.Position = cabDescriptorOffset + cabDescriptor.FileTableOffset;
            var directories = new DirectoryDescriptor[cabDescriptor.DirectoryCount];
            for (var i = 0; i < directories.Length; i++)
                directories[i] = new DirectoryDescriptor(header, cabDescriptorOffset + cabDescriptor.FileTableOffset);

            var fileGroups = new List<FileGroup>();
            foreach (var offset in fileGroupOffsets)
            {
                var nextOffset = offset;
                while (nextOffset != 0)
                {
                    header.Position = cabDescriptorOffset + (long)nextOffset + 4;
                    var descriptorOffset = header.ReadUInt32();
                    nextOffset = header.ReadUInt32();
                    header.Position = cabDescriptorOffset + descriptorOffset;

                    fileGroups.Add(new FileGroup(header, cabDescriptorOffset));
                }
            }

            header.Position = cabDescriptorOffset + cabDescriptor.FileTableOffset + cabDescriptor.FileTableOffset2;
            foreach (var fileGroup in fileGroups)
            {
                for (var i = fileGroup.FirstFile; i <= fileGroup.LastFile; i++)
                {
                    header.Position = cabDescriptorOffset +	cabDescriptor.FileTableOffset + cabDescriptor.FileTableOffset2 + i * 0x57;
                    var file = new FileDescriptor(header, i, cabDescriptorOffset + cabDescriptor.FileTableOffset);
                    var path = "{0}\\{1}\\{2}".F(fileGroup.Name, directories[file.DirectoryIndex].Name, file.Filename);
                    index[path] = file;
                }
            }
        }
Example #25
0
        public MSCabCompression(Stream stream)
        {
            this.stream = stream;

            var signature = stream.ReadASCII(4);
            if (signature != "MSCF")
                throw new InvalidDataException("Not a Microsoft CAB package!");

            stream.Position += 12;
            var filesOffset = stream.ReadUInt32();
            stream.Position += 6;
            var folderCount = stream.ReadUInt16();
            var fileCount = stream.ReadUInt16();
            if (stream.ReadUInt16() != 0)
                throw new InvalidDataException("Only plain packages (without reserved header space or prev/next archives) are supported!");

            stream.Position += 4;

            folders = new CabFolder[folderCount];
            for (var i = 0; i < folderCount; i++)
            {
                folders[i] = new CabFolder(stream);
                if (folders[i].CompressionType != 1)
                    throw new InvalidDataException("Compression type is not supported");
            }

            files = new CabFile[fileCount];
            stream.Seek(filesOffset, SeekOrigin.Begin);
            for (var i = 0; i < fileCount; i++)
                files[i] = new CabFile(stream);
        }
        public Container(Stream stream)
        {
            UInt16 stringLength = stream.ReadUInt16();
            Name = stream.ReadAsciiString(stringLength);
            ContainerType = stream.ReadUInt8();
            Flags = (ContainerFlags)stream.ReadUInt16();
            PrimitiveCount = stream.ReadUInt16();
            PackfileBaseOffset = stream.ReadUInt32();
            CompressionType = stream.ReadUInt8();
            stringLength = stream.ReadUInt16();
            StubContainerParentName = stream.ReadAsciiString(stringLength);
            Int32 auxDataSize = stream.ReadInt32();
            AuxData = new byte[auxDataSize];
            stream.Read(AuxData, 0, auxDataSize);
            TotalCompressedPackfileReadSize = stream.ReadInt32();

            Primitives = new List<Primitive>();
            PrimitiveSizes = new List<WriteTimeSizes>();

            for (UInt16 i = 0; i < PrimitiveCount; i++)
            {
                var sizes = stream.ReadStruct<WriteTimeSizes>();
                PrimitiveSizes.Add(sizes);
            }

            for (UInt16 i = 0; i < PrimitiveCount; i++)
            {
                Primitive primitive = new Primitive(stream);
                Primitives.Add(primitive);
            }
        }
Example #27
0
        private bool LoadFile( Stream stream )
        {
            string magic = stream.ReadAscii( 8 );
            uint entrySize = stream.ReadUInt32().SwapEndian();
            uint synopsisCount = stream.ReadUInt32().SwapEndian();
            uint unknown = stream.ReadUInt32().SwapEndian();
            stream.DiscardBytes( 0xC );

            SynopsisList = new List<SynopsisEntry>( (int)synopsisCount );
            for ( uint i = 0; i < synopsisCount; ++i ) {
                SynopsisEntry l = new SynopsisEntry( stream );
                SynopsisList.Add( l );
            }

            return true;
        }
Example #28
0
        TmpTDFrame[] ParseFrames(Stream s)
        {
            var start = s.Position;
            var width = s.ReadUInt16();
            var height = s.ReadUInt16();
            var size = new Size(width, height);

            s.Position += 8;
            var imgStart = s.ReadUInt32();
            s.Position += 8;
            var indexEnd = s.ReadInt32();
            var indexStart = s.ReadInt32();

            s.Position = indexStart;
            var count = indexEnd - indexStart;
            var tiles = new TmpTDFrame[count];
            var tilesIndex = 0;
            foreach (var b in s.ReadBytes(count))
            {
                if (b != 255)
                {
                    s.Position = imgStart + b * width * height;
                    tiles[tilesIndex++] = new TmpTDFrame(s.ReadBytes(width * height), size);
                }
                else
                    tiles[tilesIndex++] = new TmpTDFrame(null, size);
            }

            s.Position = start;
            return tiles;
        }
Example #29
0
		static bool IsShpTD(Stream s)
		{
			var start = s.Position;

			// First word is the image count
			var imageCount = s.ReadUInt16();
			if (imageCount == 0)
			{
				s.Position = start;
				return false;
			}

			// Last offset should point to the end of file
			var finalOffset = start + 14 + 8 * imageCount;
			if (finalOffset > s.Length)
			{
				s.Position = start;
				return false;
			}

			s.Position = finalOffset;
			var eof = s.ReadUInt32();
			if (eof != s.Length)
			{
				s.Position = start;
				return false;
			}

			// Check the format flag on the first frame
			s.Position = start + 17;
			var b = s.ReadUInt8();

			s.Position = start;
			return b == 0x20 || b == 0x40 || b == 0x80;
		}
Example #30
0
        public TmpTSReader(Stream s)
        {
            var templateWidth = s.ReadUInt32();
            var templateHeight = s.ReadUInt32();
            var tileWidth = s.ReadInt32();
            var tileHeight = s.ReadInt32();
            var size = new Size(tileWidth, tileHeight);
            var offsets = new uint[templateWidth * templateHeight];
            for (var i = 0; i < offsets.Length; i++)
                offsets[i] = s.ReadUInt32();

            for (var i = 0; i < offsets.Length; i++)
            {
                s.Position = offsets[i];
                tiles.Add(new TmpTSTile(s, size));
            }
        }