public void Open(string FileName) { using (BinaryReaderExt stream = new BinaryReaderExt(new FileStream(FileName, FileMode.Open))) { stream.BigEndian = true; Heading = stream.ReadInt32(); VersionMinor = stream.ReadByte(); VersionMajor = stream.ReadByte(); Magic = new string(stream.ReadChars(4)); stream.ReadByte(); var collisionCount = stream.ReadInt32(); for (int i = 0; i < collisionCount; i++) { LVDCollision col = new LVDCollision(); col.Read(stream, VersionMinor); Collisions.Add(col); } stream.ReadByte(); var spawnCount = stream.ReadInt32(); for (int i = 0; i < spawnCount; i++) { LVDSpawn spawn = new LVDSpawn(); spawn.Read(stream); Spawns.Add(spawn); } stream.ReadByte(); var respawnCount = stream.ReadInt32(); for (int i = 0; i < respawnCount; i++) { LVDSpawn respawn = new LVDSpawn(); respawn.Read(stream); Respawns.Add(respawn); } stream.ReadByte(); var boundsCount = stream.ReadInt32(); for (int i = 0; i < boundsCount; i++) { LVDBounds bound = new LVDBounds(); bound.Read(stream); CameraBounds.Add(bound); } stream.ReadByte(); var blastCount = stream.ReadInt32(); for (int i = 0; i < blastCount; i++) { LVDBounds blast = new LVDBounds(); blast.Read(stream); BlastZoneBounds.Add(blast); } stream.ReadByte(); int enemyGenCount = stream.ReadInt32(); for (int i = 0; i < enemyGenCount; i++) { LVDEnemyGenerator enGen = new LVDEnemyGenerator(); enGen.Read(stream); EnemyGenerators.Add(enGen); } stream.ReadByte(); if (stream.ReadInt32() > 0) { throw new NotImplementedException("Unknown LVD Section at 0x" + stream.BaseStream.Position.ToString("X")); } stream.ReadByte(); if (stream.ReadInt32() > 0) { throw new NotImplementedException("Unknown LVD Section at 0x" + stream.BaseStream.Position.ToString("X")); } stream.ReadByte(); if (stream.ReadInt32() > 0) { throw new NotImplementedException("Unknown LVD Section at 0x" + stream.BaseStream.Position.ToString("X")); } stream.ReadByte(); if (stream.ReadInt32() > 0) { throw new NotImplementedException("Unknown LVD Section at 0x" + stream.BaseStream.Position.ToString("X")); } stream.ReadByte(); if (stream.ReadInt32() > 0) { throw new NotImplementedException("Unknown LVD Section at 0x" + stream.BaseStream.Position.ToString("X")); } stream.ReadByte(); int damageCount = stream.ReadInt32(); for (int i = 0; i < damageCount; i++) { LVDDamageShape shape = new LVDDamageShape(); shape.Read(stream); DamageShapes.Add(shape); } stream.ReadByte(); int itemSpawnCount = stream.ReadInt32(); for (int i = 0; i < itemSpawnCount; i++) { LVDItemSpawner spawn = new LVDItemSpawner(); spawn.Read(stream); ItemSpawners.Add(spawn); } if (VersionMinor > 0xA) { stream.ReadByte(); int genCurveCount = stream.ReadInt32(); for (int i = 0; i < genCurveCount; i++) { LVDRangeCurve point = new LVDRangeCurve(); point.Read(stream); RangeCurves.Add(point); } stream.ReadByte(); int genCurveCount2 = stream.ReadInt32(); for (int i = 0; i < genCurveCount2; i++) { LVDGeneralVector point = new LVDGeneralVector(); point.Read(stream); GeneralVectors.Add(point); } } stream.ReadByte(); int genShapeCount = stream.ReadInt32(); for (int i = 0; i < genShapeCount; i++) { LVDGeneralShape shape = new LVDGeneralShape(); shape.Read(stream); GeneralShapes.Add(shape); } stream.ReadByte(); int genPointCount = stream.ReadInt32(); for (int i = 0; i < genPointCount; i++) { LVDGeneralPoint point = new LVDGeneralPoint(); point.Read(stream); GeneralPoints.Add(point); } stream.ReadByte(); if (stream.ReadInt32() > 0) { throw new NotImplementedException("Unknown LVD Section at 0x" + stream.BaseStream.Position.ToString("X")); } stream.ReadByte(); if (stream.ReadInt32() > 0) { throw new NotImplementedException("Unknown LVD Section at 0x" + stream.BaseStream.Position.ToString("X")); } stream.ReadByte(); if (stream.ReadInt32() > 0) { throw new NotImplementedException("Unknown LVD Section at 0x" + stream.BaseStream.Position.ToString("X")); } stream.ReadByte(); if (stream.ReadInt32() > 0) { throw new NotImplementedException("Unknown LVD Section at 0x" + stream.BaseStream.Position.ToString("X")); } if (VersionMinor > 0xA) { stream.ReadByte(); var shrunkboundsCount = stream.ReadInt32(); for (int i = 0; i < shrunkboundsCount; i++) { LVDBounds bound = new LVDBounds(); bound.Read(stream); ShrunkCameraBounds.Add(bound); } stream.ReadByte(); var shrunkblastCount = stream.ReadInt32(); for (int i = 0; i < shrunkblastCount; i++) { LVDBounds blast = new LVDBounds(); blast.Read(stream); ShrunkBlastZoneBounds.Add(blast); } } if (stream.BaseStream.Length != stream.BaseStream.Position) { stream.PrintPosition(); throw new Exception("Error fully parsing LVD " + stream.BaseStream.Position.ToString("X")); } } }
private static void ParseDebugLine(BinaryReaderExt r) { // read header var debug_line_header = new ELF_Debug_Line() { length = r.ReadUInt32(), version = r.ReadUInt16(), header_length = r.ReadUInt32(), min_instruction_length = r.ReadByte(), default_is_stmt = r.ReadByte(), line_base = r.ReadSByte(), line_range = r.ReadByte(), opcode_base = r.ReadByte(), std_opcode_lengths = new byte[12] }; for (int k = 0; k < 12; k++) { debug_line_header.std_opcode_lengths[k] = r.ReadByte(); } // read directories while (r.PeekChar() != 0) { Debug.WriteLine(r.ReadString()); } r.Skip(1); // read files while (r.PeekChar() != 0) { Debug.WriteLine(r.ReadString() + " " + r.ReadByte() + " " + r.ReadByte() + " " + r.ReadByte()); } r.PrintPosition(); int address = 0; int op_index = 0; int file = 1; int line = 1; int column = 0; bool is_stmt = debug_line_header.default_is_stmt != 0; bool basic_block = false; bool end_sequence = false; bool prologue_end = false; bool epilogue_begin = false; int isa = 0; int dicriminator = 0; var op_code_start = r.Position; while (true) { var op = r.ReadByte(); switch (op) { case 0: // extended byte ReadLEB123(r); break; } } }