public void Deserialize(Stream stream)
		{
			List<PackageEntry> entries = new List<PackageEntry>();

			// Types
			while (true)
			{
				string typeName = stream.ReadASCIIZ();
				if (typeName == "")
				{
					break;
				}

				// Directories
				while (true)
				{
					string directoryName = stream.ReadASCIIZ();
					if (directoryName == "")
					{
						break;
					}

					// Files
					while (true)
					{
						string fileName = stream.ReadASCIIZ();
						if (fileName == "")
						{
							break;
						}

						PackageEntry entry = new PackageEntry();
						entry.FileName = fileName;
						entry.DirectoryName = directoryName.Replace("/", "\\");
						entry.TypeName = typeName;
						entry.HashOrTimestamp = stream.ReadU32();
						entry.SmallData = new byte[stream.ReadU16()];
						entry.ArchiveIndex = stream.ReadU16();
						entry.Offset = stream.ReadU32();
						entry.Size = stream.ReadU32();
						entry.Unknown = stream.ReadU16();

						if (entry.Unknown != 0xFFFF)
						{
							throw new PackageFileException();
						}

						if (entry.SmallData.Length > 0)
						{
							stream.Read(entry.SmallData, 0, entry.SmallData.Length);
						}

						entries.Add(entry);
					}
				}
			}

			this.Entries = entries;
		}
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 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 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 #5
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 FileDescriptor(Stream reader, long tableOffset)
			{
				Flags = reader.ReadUInt16();
				ExpandedSize = reader.ReadUInt32();
				/*    unknown   */ reader.ReadUInt32();
				CompressedSize = reader.ReadUInt32();

				/*  unknown */ reader.ReadUInt32();
				DataOffset   = reader.ReadUInt32();
				/*  unknown */ reader.ReadUInt32();
				MD5          = reader.ReadBytes(16);

				/*   unknown  */ reader.ReadBytes(16);
				NameOffset     = reader.ReadUInt32();
				DirectoryIndex = reader.ReadUInt16();
				/*   unknown  */ reader.ReadBytes(12);
				LinkToPrevious = reader.ReadUInt32();
				LinkToNext = reader.ReadUInt32();

				LinkFlags = reader.ReadBytes(1)[0];
				Volume = reader.ReadUInt16();
				var posSave = reader.Position;

				reader.Seek(tableOffset + NameOffset, SeekOrigin.Begin);
				Filename = reader.ReadASCIIZ();
				reader.Seek(posSave, SeekOrigin.Begin);
			}
            public FileGroup(Stream stream, long offset)
            {
                var nameOffset = stream.ReadUInt32();
                stream.Position += 18;
                FirstFile = stream.ReadUInt32();
                LastFile = stream.ReadUInt32();

                var pos = stream.Position;
                stream.Position = offset + nameOffset;
                Name = stream.ReadASCIIZ();
                stream.Position = pos;
            }
            public FileDescriptor(Stream stream, uint index, long tableOffset)
            {
                Index = index;
                Flags = (CABFlags)stream.ReadUInt16();
                ExpandedSize = stream.ReadUInt32();
                stream.Position += 4;
                CompressedSize = stream.ReadUInt32();

                stream.Position += 4;
                DataOffset = stream.ReadUInt32();
                stream.Position += 4;
                MD5 = stream.ReadBytes(16);

                stream.Position += 16;
                NameOffset = stream.ReadUInt32();
                DirectoryIndex = stream.ReadUInt16();
                stream.Position += 12;
                LinkToPrevious = stream.ReadUInt32();
                LinkToNext = stream.ReadUInt32();

                LinkFlags = (LinkFlags)stream.ReadUInt8();
                Volume = stream.ReadUInt16();

                var pos = stream.Position;
                stream.Position = tableOffset + NameOffset;
                Filename = stream.ReadASCIIZ();
                stream.Position = pos;
            }
            public DirectoryDescriptor(Stream stream, long nameTableOffset)
            {
                var nameOffset = stream.ReadUInt32();
                var pos = stream.Position;

                stream.Position = nameTableOffset + nameOffset;

                Name = stream.ReadASCIIZ();
                stream.Position = pos;
            }
Example #10
0
 public CabFile(Stream stream)
 {
     DecompressedLength = stream.ReadUInt32();
     DecompressedOffset = stream.ReadUInt32();
     FolderIndex = stream.ReadUInt16();
     stream.Position += 6;
     FileName = stream.ReadASCIIZ();
 }