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; }
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; }
public WdFile(Stream stream, string filename) { this.stream = stream; Name = filename; var numFiles = stream.ReadUInt32(); if (numFiles == 0) { return; // TODO implement sound container support } for (var i = 0; i < numFiles; i++) { var entry = new WdEntry { Offset = stream.ReadInt32(), Length = stream.ReadInt32() }; /*var unk3 = */ stream.ReadUInt32(); // 0x00 /*var unk4 = */ stream.ReadUInt32(); // 0x00 /*var unk5 = */ stream.ReadUInt32(); // 0x00 var filePathOffset = stream.ReadUInt32(); var originalPosition = stream.Position; stream.Position = numFiles * 24 + 8 + filePathOffset; index.Add(stream.ReadASCIIZ(), entry); stream.Position = originalPosition; } }
public void Read(Stream stream) { if (stream.ReadASCII(4) != "EMHF") // FHME = 'Firehawk Mission Entities' { throw new Exception(); } if (stream.ReadU32BE() != 14) // version { throw new Exception(); } while (stream.Position < stream.Length) { uint unk1 = stream.ReadU32BE(); uint size = stream.ReadU32BE(); long next = stream.Position + size; if (unk1 == 0) { string name = stream.ReadASCIIZ(1024); } else { throw new Exception(); } stream.Seek(next, SeekOrigin.Begin); } }
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; } }
public D2kSoundResources(FileSystem context, string filename, int priority) { this.filename = filename; this.priority = priority; s = context.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; } }
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 D2kSoundResources(string filename, int priority) { this.filename = filename; this.priority = priority; s = GlobalFileSystem.Open(filename); s.Seek(0, SeekOrigin.Begin); 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); } }
public PakFile(Stream stream, string filename) { Name = filename; this.stream = stream; try { 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 PakFile(FileSystem context, string filename) { Name = filename; index = new Dictionary <string, Entry>(); stream = context.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 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 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 PakFile(string filename, int priority) { this.filename = filename; this.priority = priority; index = new Dictionary <string, Entry>(); stream = GlobalFileSystem.Open(filename); 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; } }
public CabFile(Stream stream) { DecompressedLength = stream.ReadUInt32(); DecompressedOffset = stream.ReadUInt32(); FolderIndex = stream.ReadUInt16(); stream.Position += 6; FileName = stream.ReadASCIIZ(); }
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(); }
public DirectoryDescriptor(Stream stream, long nameTableOffset) { var nameOffset = stream.ReadUInt32(); var pos = stream.Position; stream.Position = nameTableOffset + nameOffset; Name = stream.ReadASCIIZ(); stream.Position = pos; }
public FileGroup(Stream reader, long offset) { var nameOffset = reader.ReadUInt32(); /* unknown */ reader.ReadBytes(18); FirstFile = reader.ReadUInt32(); LastFile = reader.ReadUInt32(); reader.Seek(offset + nameOffset, SeekOrigin.Begin); Name = reader.ReadASCIIZ(); }
public void Read(Stream stream) { if (stream.ReadASCII(4) != "MMHF") // FHMM = 'Firehawk Mission Models' { throw new Exception(); } if (stream.ReadU32BE() != 14) // version { throw new Exception(); } while (stream.Position < stream.Length) { uint unk1 = stream.ReadU32BE(); uint size = stream.ReadU32BE(); long next = stream.Position + size; if (unk1 == 0) { uint unk2 = stream.ReadU32BE(); if (unk2 == 1) { uint unk3 = stream.ReadU32BE(); string name = stream.ReadASCIIZ(1024); string path; path = Path.Combine("tests", "unknown"); Directory.CreateDirectory(path); path = Path.Combine(path, Path.ChangeExtension(name, ".bin")); Stream output = File.OpenWrite(path); byte[] data = new byte[next - stream.Position]; stream.Read(data, 0, data.Length); output.Write(data, 0, data.Length); output.Flush(); output.Close(); } else { throw new Exception(); } } else { throw new Exception(); } stream.Seek(next, SeekOrigin.Begin); } }
public Entry(Stream s) { Offset = s.ReadUInt32(); Size = s.ReadUInt32(); if (BitConverter.IsLittleEndian) { Offset = int2.Swap(Offset); Size = int2.Swap(Size); } Path = s.ReadASCIIZ(); }
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 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 static void ReadDirectory(string parentDirectory, Stream input) { string path; string currentDirectory = input.ReadASCIIZ(); if (parentDirectory == null) { path = ""; // currentDirectory; } else { path = Path.Combine(parentDirectory, currentDirectory); } uint fileCount = input.ReadU32BE(); for (uint i = 0; i < fileCount; i++) { FileEntry entry = new FileEntry(); entry.Size = input.ReadU32BE(); entry.Path = Path.Combine(path, input.ReadASCIIZ()); entry.Offset = input.ReadU32BE(); if (entry.Offset != 0xFFFFFFFF) { Files.Add(entry); Console.WriteLine(Path.Combine(path, entry.Path)); } } uint dirCount = input.ReadU32BE(); for (uint i = 0; i < dirCount; i++) { ReadDirectory(path, input); } }
public string DirectoryName(uint index) { if (directoryNames.ContainsKey(index)) { return(directoryNames[index]); } hdrFile.Seek(commonHeader.CabDescriptorOffset + cabDescriptor.FileTableOffset + directoryTable[(int)index], SeekOrigin.Begin); var test = hdrFile.ReadASCIIZ(); return(test); }
public D2kSoundResources(Stream s, string filename) { Name = filename; this.s = s; try { var headerLength = s.ReadUInt32(); while (s.Position < headerLength + 4) { var name = s.ReadASCIIZ(); var offset = s.ReadUInt32(); var length = s.ReadUInt32(); index.Add(name, new Entry(offset, length)); } } catch { Dispose(); throw; } }
public D2kSoundResources(FileSystem context, string filename) { Name = filename; s = context.Open(filename); try { var headerLength = s.ReadUInt32(); while (s.Position < headerLength + 4) { var name = s.ReadASCIIZ(); var offset = s.ReadUInt32(); var length = s.ReadUInt32(); index.Add(name, new Entry(offset, length)); } } catch { Dispose(); throw; } }
public void Read(Stream stream) { this.Entries.Clear(); uint magic = BigEndian ? stream.ReadU32BE() : stream.ReadU32(); // 00 if (magic != 0x564B4547) { throw new NotAPegFileException("header must be GEKV"); } ushort version = BigEndian ? stream.ReadU16BE() : stream.ReadU16(); // 04 if (version != 10) { throw new UnsupportedPackageFileVersionException("only version 10 is supported"); } Unknown06 = BigEndian ? stream.ReadU16BE() : stream.ReadU16(); // 06 this.FileSize = BigEndian ? stream.ReadU32BE() : stream.ReadU32(); // 08 if (stream.Length != this.FileSize) { throw new PegFileException("size of file does not match size in header"); } this.DataFileSize = BigEndian ? stream.ReadU32BE() : stream.ReadU32(); // 0C ushort entryCount = BigEndian ? stream.ReadU16BE() : stream.ReadU16(); // 10 this.Unknown12 = BigEndian ? stream.ReadU16BE() : stream.ReadU16(); // 12 ushort frameCount = BigEndian ? stream.ReadU16BE() : stream.ReadU16();; // 14 this.Unknown16 = BigEndian ? stream.ReadU16BE() : stream.ReadU16();; // 16 // Read names string[] names = new string[entryCount]; stream.Seek(0x18 + (0x30 * frameCount), SeekOrigin.Begin); for (int i = 0; i < entryCount; i++) { names[i] = stream.ReadASCIIZ(); } int totalFrames = 0; // Read entries stream.Seek(0x18, SeekOrigin.Begin); for (int i = 0; i < entryCount; i++) { PegEntry entry = new PegEntry(); entry.Name = names[i]; PegFrame frame = this.ReadFrame(stream); entry.Frames.Add(frame); totalFrames++; if (frame.Frames == 0) { throw new Exception("frame count is 0"); } else if (frame.Frames > 1) { /* The first frame of a peg will say how many frames are in the * image (including itself), all subsequent frames have 1 for the * frame count. */ for (int j = 1; j < frame.Frames; j++) { entry.Frames.Add(this.ReadFrame(stream)); totalFrames++; } } this.Entries.Add(entry); } if (totalFrames != frameCount) { throw new Exception("something bad happened"); } }
public VolFile(Stream stream, string filename) { Name = filename; this.stream = stream; var magicByte = stream.ReadASCII(4); if (magicByte != "VOL ") { return; } var unknown1 = stream.ReadUInt32(); var header = stream.ReadASCII(4); var zero = stream.ReadUInt32(); if (header != "volh" && zero != 0) { return; } var volumeSection = stream.ReadASCII(4); if (volumeSection != "vols") { return; } var unknown2 = stream.ReadUInt32(); var directoryOffset = stream.ReadUInt32(); var entryFilenames = new List <string>(); while (true) { var entryFilename = stream.ReadASCIIZ(); if (string.IsNullOrEmpty(entryFilename)) { break; } entryFilenames.Add(entryFilename); } while (true) { if (stream.ReadByte() != 0) { break; } } stream.Seek(-1, SeekOrigin.Current); var volumeIndex = stream.ReadASCII(4); if (volumeIndex != "voli") { return; } var totalSize = stream.ReadUInt32(); foreach (var entryFilename in entryFilenames) { var filenameIndex = stream.ReadUInt32(); var offset = stream.ReadUInt32(); var size = stream.ReadUInt32(); var compression = stream.ReadByte(); var valid = stream.ReadByte(); if (valid != 0 && valid != 1) { throw new InvalidDataException("Check byte contains invalid values"); } // Ignore duplicate files if (index.ContainsKey(entryFilename)) { continue; } var info = new VolEntry() { Filename = entryFilename, Offset = offset + 8, Size = size, Compression = compression, }; if (compression != 0) { throw new NotImplementedException("'RLE', 'LZ', 'LZH' are not yet supported."); } index.Add(entryFilename, info); } }
public void Read(Stream stream) { stream.ReadU32(); // crc int version = stream.ReadS32(); if (version != 82) { throw new Exception(); } if (stream.ReadU32() != 0) // { throw new Exception(); } // Configuration this.Model.PlayerModel = stream.ReadASCIIZ(260); this.Model.WeaponPackModel = stream.ReadASCIIZ(260); this.Config.DifficultyLevel = stream.ReadS32(); this.Config.Input.InvertYAxis = stream.ReadS32(); this.Config.Input.InvertCamera = stream.ReadS32(); this.Config.Input.InvertCameraX = stream.ReadS32(); this.Config.Input.InvertThrottle = stream.ReadS32(); this.Config.Input.InvertYaw = stream.ReadS32(); this.Config.CameraMode = stream.ReadASCIIZ(32); this.Config.Hud.RenderTheHudOption = stream.ReadS32(); this.Config.Input.GameplayMouseDisable = stream.ReadS32(); this.Config.Hud.MeasurementsStyle = stream.ReadS32(); this.Config.Hud.Subtitles = stream.ReadS32(); this.Config.Menus.HasPlayedOffMode = stream.ReadS32(); this.Config.Input.CurrentScheme = stream.ReadS32(); this.Config.Input.EnableExpertControls = stream.ReadS32(); this.Config.Sound.Music = stream.ReadF32(); this.Config.Sound.Voices = stream.ReadF32(); this.Config.Sound.MasterSFX = stream.ReadF32(); this.Config.VoiceComm.DefaultState = stream.ReadS32(); this.Config.VoiceComm.ControlMethod = stream.ReadS32(); // Onward, ho! this.Cheated = stream.ReadS32(); this.Unknown02 = stream.ReadS32(); this.Unknown03 = stream.ReadS32(); this.Unknown04 = stream.ReadS32(); /* There are 19 missions in retail HAWX. Unfortunately this design means * if the mission count *ever* changes, the profiles become corrupt (argh). */ for (int i = 0; i < this.Missions.Length; i++) { this.Missions[i] = new MissionProfileData(); this.Missions[i].Read(stream); } /* There are 67 planes in retail HAWX. Unfortunately this design means * if the plane count *ever* changes, the profiles become corrupt (argh). */ for (int i = 0; i < this.Planes.Length; i++) { this.Planes[i] = new PlaneProfileData(); this.Planes[i].Read(stream, i); } /* There are 303 challenges in retail HAWX. Unfortunately this design means * if the challenge count *ever* changes, the profiles become corrupt (argh). */ for (int i = 0; i < this.Challenges.Length; i++) { this.Challenges[i] = new ChallengeProfileData(); this.Challenges[i].Read(stream); } int count = stream.ReadS32(); this.Unknown05 = new UnknownProfileData[count]; for (int i = 0; i < count; i++) { this.Unknown05[i] = new UnknownProfileData(); this.Unknown05[i].Read(stream); } int unknownSize = stream.ReadS32(); this.Unknown06 = new int[(int)Math.Floor((double)((unknownSize / 32) + 1))]; for (int i = 0; i < this.Unknown06.Length; i++) { this.Unknown06[i] = stream.ReadS32(); } this.Unknown07 = new byte[unknownSize]; stream.Read(this.Unknown07, 0, unknownSize); this.Unknown08 = stream.ReadS32(); this.Unknown09 = stream.ReadS32(); this.Unknown10 = stream.ReadS32(); this.XP = stream.ReadS32(); this.Unknown11 = stream.ReadS32(); this.Unknown12 = stream.ReadS32(); this.Unknown13 = stream.ReadS32(); this.Callsign = stream.ReadUTF16LEZ(12); this.Unknown14 = stream.ReadS32(); }
public void Read(Stream stream) { this.CachedFiles.Clear(); int count = stream.ReadS32BE(); for (int i = 0; i < count; i++) { IniCacheCachedFile entry = new IniCacheCachedFile(); entry.Name = stream.ReadASCIIZ(); entry.Offset = stream.ReadU32BE(); entry.Size = stream.ReadU32BE(); this.CachedFiles.Add(entry); } foreach (IniCacheCachedFile entry in this.CachedFiles) { stream.Seek(entry.Offset, SeekOrigin.Begin); SortedDictionary <string, object> section = null; while (stream.Position < entry.Offset + entry.Size) { byte keyType = stream.ReadU8(); if (keyType == 0) // section { section = new SortedDictionary <string, object>(); string name = stream.ReadASCIIZ(); entry.Sections[name] = section; } else if (keyType == 1) // key { string name = stream.ReadASCIIZ(); IniTypes.Base value = null; switch (stream.ReadU8()) { case 0: value = new IniTypes.Integer(); break; case 2: value = new IniTypes.Float(); break; case 4: value = new IniTypes.String(); break; case 10: value = new IniTypes.Vector(); break; case 14: value = new IniTypes.Boolean(); break; case 16: value = new IniTypes.Rectangle(); break; case 18: value = new IniTypes.Position(); break; case 20: value = new IniTypes.Color(); break; default: throw new Exception(); } value.Read(stream); section[name] = value; } else { throw new Exception(); } } } }
public override void Read(Stream stream) { this.Value = stream.ReadASCIIZ(); }
public static string ReadASCIIZ(this Stream stream) { return(stream.ReadASCIIZ(0)); }