public UndoableMapModel CreateFromHpi(string hpipath, string mappath, bool readOnly) { MapModel m; using (var hpi = new HpiArchive(hpipath)) { var otaPath = HpiPath.ChangeExtension(mappath, ".ota"); TdfNode n; var otaFileInfo = hpi.FindFile(otaPath); var otaFileBuffer = new byte[otaFileInfo.Size]; hpi.Extract(otaFileInfo, otaFileBuffer); using (var ota = new MemoryStream(otaFileBuffer)) { n = TdfNode.LoadTdf(ota); } var tntFileInfo = hpi.FindFile(mappath); var tntFileBuffer = new byte[tntFileInfo.Size]; hpi.Extract(tntFileInfo, tntFileBuffer); using (var s = new TntReader(new MemoryStream(tntFileBuffer))) { m = this.mapModelFactory.FromTntAndOta(s, n); } } return(new UndoableMapModel(m, hpipath, readOnly)); }
protected override void LoadFile(HpiArchive archive, HpiArchive.FileInfo file) { // extract and read the file var fileBuffer = new byte[file.Size]; archive.Extract(file, fileBuffer); var adapter = new GafEntryArrayAdapter(); using (var b = new GafReader(new MemoryStream(fileBuffer), adapter)) { b.Read(); } var gaf = adapter.Entries; var records = this.filenameFeatureMap[HpiPath.GetFileNameWithoutExtension(file.Name)]; // retrieve the anim for each record foreach (var record in records) { var sequenceName = record.SequenceName; if (string.IsNullOrEmpty(sequenceName)) { // Skip if this record has no sequence name. continue; } var entry = gaf.FirstOrDefault( x => string.Equals(x.Name, sequenceName, StringComparison.OrdinalIgnoreCase)); if (entry == null) { // skip if the sequence is not in this gaf file continue; } var frame = entry.Frames[0]; Bitmap bmp; if (frame.Data == null || frame.Width == 0 || frame.Height == 0) { bmp = new Bitmap(50, 50); } else { bmp = BitmapConvert.ToBitmap( frame.Data, frame.Width, frame.Height, frame.TransparencyIndex); } var offsetImage = new OffsetBitmap(-frame.OffsetX, -frame.OffsetY, bmp); this.Records.Add(new KeyValuePair <string, OffsetBitmap>(record.Name, offsetImage)); } }
protected override void LoadFile(HpiArchive archive, HpiArchive.FileInfo file) { var fileBuffer = new byte[file.Size]; archive.Extract(file, fileBuffer); TdfNode n; using (var tdf = new MemoryStream(fileBuffer)) { n = TdfNode.LoadTdf(tdf); } this.Records.AddRange( n.Keys.Values.Select(FeatureRecord.FromTdfNode)); }
protected override void LoadFile(HpiArchive archive, HpiArchive.FileInfo file) { var records = this.objectMap[HpiPath.GetFileNameWithoutExtension(file.Name)]; var fileBuffer = new byte[file.Size]; archive.Extract(file, fileBuffer); using (var b = new MemoryStream(fileBuffer)) { var adapter = new ModelEdgeReaderAdapter(); var reader = new ModelReader(b, adapter); reader.Read(); var wire = Util.RenderWireframe(adapter.Edges); foreach (var record in records) { this.Records.Add(new KeyValuePair <string, OffsetBitmap>(record.Name, wire)); } } }
protected override void LoadFile(HpiArchive archive, HpiArchive.FileInfo file) { var fileBuffer = new byte[file.Size]; archive.Extract(file, fileBuffer); using (var s = new SctReader(new MemoryStream(fileBuffer))) { var section = new Section(archive.FileName, file.FullPath); section.Name = HpiPath.GetFileNameWithoutExtension(file.Name); section.Minimap = SectionFactory.MinimapFromSct(s); section.DataWidth = s.DataWidth; section.DataHeight = s.DataHeight; var directoryString = HpiPath.GetDirectoryName(file.FullPath); Debug.Assert(directoryString != null, "Null directory for section in HPI."); var directories = directoryString.Split('\\'); section.World = directories[1]; section.Category = directories[2]; this.Records.Add(section); } }
private MapTile LoadSectionFromDisk(string hpiFileName, string sctFileName) { var outpath = Path.GetTempFileName(); try { byte[] fileBuffer; using (var h = new HpiArchive(hpiFileName)) { var fileInfo = h.FindFile(sctFileName); fileBuffer = new byte[fileInfo.Size]; h.Extract(fileInfo, fileBuffer); } using (var s = new SctReader(new MemoryStream(fileBuffer))) { return(this.sectionFactory.TileFromSct(s)); } } finally { File.Delete(outpath); } }