private void CheckFilePosition(IEXEntry entry) { if (_reader.BaseStream.Position != entry.EntryEnd) { throw new Exception("Failed to parse entry!"); } }
private IEXEntry[] ReadEntryTable(BinaryReader reader) { uint numEntries = reader.ReadUInt32(); IEXEntry[] array = new IEXEntry[numEntries]; for (uint x = 0; x < numEntries; x++) { byte header = reader.ReadByte(); if (header == 0x00) { array[x] = null; continue; } else if (header != 0x01) { throw new Exception("Unexpected header!"); } array[x] = ReadEntry(reader); } return(array); }
public void Read(BinaryReader reader) { _reader = reader; ReadHeader(reader); ReadStrings(reader); ReadGraphicsLookup(reader); ReadSoundLookup(reader); SoundEntries = ReadEntryTable(reader); FontEntires = ReadEntryTable(reader); CursorEntries = ReadEntryTable(reader); TileEntries = ReadEntryTable(reader); ObjectEntries = ReadEntryTable(reader); CollisionEntries = ReadEntryTable(reader); ParticleEntries = ReadEntryTable(reader); UnknownEntry = ReadEntry(reader); FunctonTable1 = ReadEntry(reader); FunctonTable2 = ReadEntry(reader); LevelEntries = ReadNamedEntryTable(reader); GUIEntries = ReadNamedEntryTable(reader); if (reader.BaseStream.Position != reader.BaseStream.Length) { throw new Exception("Failed to parse IEX successfully!"); } }
public void CopyEntryToStream(IEXEntry entry, Stream target) { JumpToEntry(entry); byte[] buffer = _reader.ReadBytes(entry.Length); target.Write(buffer, 0, buffer.Length); CheckFilePosition(entry); }
public CollisionData ReadCollisionData(IEXEntry entry) { JumpToEntry(entry); CollisionData collision = CollisionData.Read(_reader); CheckFilePosition(entry); return(collision); }
public ObjectData ReadObjectData(IEXEntry entry) { JumpToEntry(entry); ObjectData obj = ObjectData.Read(_reader); CheckFilePosition(entry); return(obj); }
public CursorData ReadCursorData(IEXEntry entry) { JumpToEntry(entry); CursorData font = CursorData.Read(_reader); CheckFilePosition(entry); return(font); }
public FontData ReadFontData(IEXEntry entry) { JumpToEntry(entry); FontData font = FontData.Read(_reader); CheckFilePosition(entry); return(font); }
public SoundData ReadSoundData(IEXEntry entry) { JumpToEntry(entry); SoundData data = SoundData.Read(_reader); CheckFilePosition(entry); return(data); }
public LevelData ReadLevelData(IEXEntry entry) { JumpToEntry(entry); LevelData level = LevelData.Read(_reader); CheckFilePosition(entry); return(level); }
public GUIData ReadGUIData(IEXEntry entry) { JumpToEntry(entry); GUIData gui = GUIData.Read(_reader); CheckFilePosition(entry); return(gui); }
public ParticleData ReadParticleData(IEXEntry entry) { JumpToEntry(entry); ParticleData particle = ParticleData.Read(_reader); CheckFilePosition(entry); return(particle); }
private void WriteNamedEntryList(BinaryWriter writer, IEXEntry[] list) { writer.Write((uint)list.Length); for (uint x = 0; x < list.Length; x++) { IEXEntry entry = list[x]; WriteNamedEntry(writer, entry); } }
//Read unnamed entries private IEXEntry ReadEntry(BinaryReader reader) { uint dataLength = reader.ReadUInt32(); long dataEnd = reader.BaseStream.Position + dataLength; IEXEntry entry = new IEXEntry(dataLength, reader.BaseStream.Position); reader.BaseStream.Position = dataEnd; return(entry); }
private void WriteEntry(BinaryWriter writer, IEXEntry entry) { writer.Write((uint)entry.Length); writer.Flush(); using (FileStream data = File.OpenRead(entry.SourceFile)) { data.CopyTo(writer.BaseStream); } }
//Read named entries private IEXEntry ReadNamedEntry(BinaryReader reader) { string name = reader.ReadTString(); uint dataLength = reader.ReadUInt32(); long dataEnd = reader.BaseStream.Position + dataLength; IEXEntry entry = new IEXEntry(dataLength, reader.BaseStream.Position, name); reader.BaseStream.Position = dataEnd; return(entry); }
private IEXEntry[] ReadNamedEntryTable(BinaryReader reader) { uint numEntries = reader.ReadUInt32(); IEXEntry[] array = new IEXEntry[numEntries]; for (uint x = 0; x < numEntries; x++) { array[x] = ReadNamedEntry(reader); } return(array); }
public TileData ReadTileData(IEXEntry entry) { JumpToEntry(entry); uint magicNumber = _reader.ReadUInt32(); //Tile count? if (magicNumber != 0x01) { throw new Exception("Unexpected tile count");; } TileData tile = TileData.Read(_reader); CheckFilePosition(entry); return(tile); }
public GameFunction[] ReadFunctionTable(IEXEntry entry) { JumpToEntry(entry); uint entries = _reader.ReadUInt32(); GameFunction[] array = new GameFunction[entries]; for (uint x = 0; x < entries; x++) { array[x] = GameFunction.ReadFunction(_reader); } CheckFilePosition(entry); return(array); }
private void WriteIndexedEntryList(BinaryWriter writer, IEXEntry[] list) { writer.Write((uint)list.Length); for (uint x = 0; x < list.Length; x++) { IEXEntry entry = list[x]; if (entry == null) { writer.Write((byte)0x00); continue; } writer.Write((byte)0x01); WriteEntry(writer, entry); } }
private void JumpToEntry(IEXEntry entry) { _reader.BaseStream.Position = entry.FileOffset; }