public static AptFile CreateEmpty(string name, int width, int height, int millisecondsPerFrame) { var constData = new ConstantData(); var apt = new AptFile(constData, null, name) { ImageMap = new ImageMap(), GeometryMap = new Dictionary <uint, Geometry>() }; apt.Movie = Movie.CreateEmpty(apt, width, height, millisecondsPerFrame); return(apt); }
public static AptFile FromFileSystemEntry(FileSystemEntry entry) { using (var stream = entry.Open()) using (var reader = new BinaryReader(stream, Encoding.ASCII, true)) { //check if this is a valid apt file var magic = reader.ReadFixedLengthString(8); if (magic != "Apt Data") { throw new InvalidDataException(); } //load the corresponding const entry var constPath = Path.ChangeExtension(entry.FilePath, ".const"); var constFile = ConstantData.FromFileSystemEntry(entry.FileSystem.GetFile(constPath)); var aptName = Path.GetFileNameWithoutExtension(entry.FilePath); var apt = new AptFile(constFile, entry.FileSystem, aptName); apt.Parse(reader); return(apt); } }
public static ConstantData FromFileSystemEntry(FileSystemEntry entry) { using (var stream = entry.Open()) using (var reader = new BinaryReader(stream)) { var data = new ConstantData(); //validate that this is a correct const var magic = reader.ReadFixedLengthString(17); if (magic != "Apt constant file") { throw new InvalidDataException($"Not a supported const file: {magic}"); } reader.BaseStream.Seek(3, SeekOrigin.Current); data.AptDataEntryOffset = reader.ReadUInt32(); var numEntries = reader.ReadUInt32(); var headerSize = reader.ReadUInt32(); if (headerSize != 32) { throw new InvalidDataException("Constant header must be 32 bytes"); } for (var i = 0; i < numEntries; i++) { var constEntry = new ConstantEntry { Type = reader.ReadUInt32AsEnum <ConstantEntryType>() }; //read the number/ string offset switch (constEntry.Type) { case ConstantEntryType.Undef: throw new InvalidDataException("Undefined const entry"); case ConstantEntryType.String: var strOffset = reader.ReadUInt32(); var pos = reader.BaseStream.Position; reader.BaseStream.Seek(strOffset, SeekOrigin.Begin); constEntry.Value = reader.ReadNullTerminatedString(); reader.BaseStream.Seek(pos, SeekOrigin.Begin); break; case ConstantEntryType.Register: constEntry.Value = reader.ReadUInt32(); break; case ConstantEntryType.Boolean: constEntry.Value = reader.ReadBooleanUInt32Checked(); break; case ConstantEntryType.Float: constEntry.Value = reader.ReadSingle(); break; case ConstantEntryType.Integer: constEntry.Value = reader.ReadInt32(); break; case ConstantEntryType.Lookup: constEntry.Value = reader.ReadUInt32(); break; default: throw new InvalidDataException(); } data.Entries.Add(constEntry); } return(data); } }
private AptFile(ConstantData constants, FileSystem filesystem, string name) { Constants = constants; FileSystem = filesystem; MovieName = name; }
public static ConstantData FromFileSystemEntry(FileSystemEntry entry) { using (var stream = entry.Open()) using (var reader = new BinaryReader(stream)) { var data = new ConstantData(); //validate that this is a correct const var magic = reader.ReadFixedLengthString(17); if (magic != "Apt constant file") { throw new InvalidDataException($"Not a supported const file: {magic}"); } reader.BaseStream.Seek(3, SeekOrigin.Current); data.AptDataEntryOffset = reader.ReadUInt32(); var numEntries = reader.ReadUInt32(); reader.BaseStream.Seek(4, SeekOrigin.Current); for (var i = 0; i < numEntries; i++) { var constEntry = new ConstantEntry { Type = reader.ReadUInt32AsEnum <ConstantEntryType>() }; //read the number/ string offset var entryValue = reader.ReadUInt32(); switch (constEntry.Type) { case ConstantEntryType.Undef: throw new InvalidDataException("Undefined const entry"); case ConstantEntryType.String: var pos = reader.BaseStream.Position; reader.BaseStream.Seek(entryValue, SeekOrigin.Begin); constEntry.Value = reader.ReadNullTerminatedString(); reader.BaseStream.Seek(pos, SeekOrigin.Begin); break; case ConstantEntryType.Number: constEntry.Value = entryValue; break; case ConstantEntryType.Unknown1: // TODO break; case ConstantEntryType.Unknown2: // TODO break; case ConstantEntryType.Unknown3: // TODO break; case ConstantEntryType.Unknown4: // TODO break; case ConstantEntryType.Unknown5: // TODO break; default: throw new InvalidDataException(); } data.Entries.Add(constEntry); } return(data); } }