public override ArcFile TryOpen(ArcView file) { if ('B' != file.View.ReadByte(0) || 'M' != file.View.ReadByte(1)) { return(null); } int type = file.View.ReadSByte(0x1C); if (type != 1 && type != 2) { return(null); } int count = file.View.ReadInt16(0x3A); if (!IsSaneCount(count)) { return(null); } uint width = file.View.ReadUInt32(0x12); uint height = file.View.ReadUInt32(0x16); int pixel_size = 2 == type ? 4 : 3; uint bitmap_data_size = width * height * (uint)pixel_size; var dir = new List <Entry> (count); long next_offset = file.View.ReadUInt32(0x42); uint current_offset = 0x46; string base_name = Path.GetFileNameWithoutExtension(file.Name); for (int i = 0; i < count; ++i) { var entry = new AbmEntry { Name = string.Format("{0}#{1:D4}", base_name, i), Type = "image", Offset = next_offset, Index = i, }; if (i + 1 != count) { next_offset = file.View.ReadUInt32(current_offset); current_offset += 4; } else { next_offset = file.MaxOffset; } if (next_offset <= entry.Offset) { return(null); } entry.Size = (uint)(next_offset - entry.Offset); if (!entry.CheckPlacement(file.MaxOffset)) { return(null); } entry.UnpackedSize = 0x12 + bitmap_data_size; dir.Add(entry); } var image_info = new AbmImageData { Width = (uint)width, Height = (uint)height, BPP = pixel_size * 8, Mode = type, BaseOffset = (uint)dir[0].Offset, }; return(new AbmArchive(file, this, dir, image_info)); }
public override ArcFile TryOpen(ArcView file) { if ('B' != file.View.ReadByte (0) || 'M' != file.View.ReadByte (1)) return null; int type = file.View.ReadSByte (0x1C); if (type != 1 && type != 2) return null; int count = file.View.ReadInt16 (0x3A); if (!IsSaneCount (count)) return null; uint width = file.View.ReadUInt32 (0x12); uint height = file.View.ReadUInt32 (0x16); int pixel_size = 2 == type ? 4 : 3; uint bitmap_data_size = width*height*(uint)pixel_size; var dir = new List<Entry> (count); long next_offset = file.View.ReadUInt32 (0x42); uint current_offset = 0x46; string base_name = Path.GetFileNameWithoutExtension (file.Name); for (int i = 0; i < count; ++i) { var entry = new AbmEntry { Name = string.Format ("{0}#{1:D4}.tga", base_name, i), Type = "image", Offset = next_offset, Index = i, }; if (i + 1 != count) { next_offset = file.View.ReadUInt32 (current_offset); current_offset += 4; } else next_offset = file.MaxOffset; if (next_offset <= entry.Offset) return null; entry.Size = (uint)(next_offset - entry.Offset); if (!entry.CheckPlacement (file.MaxOffset)) return null; entry.UnpackedSize = 0x12 + bitmap_data_size; dir.Add (entry); } var image_info = new AbmImageData { Width = (uint)width, Height = (uint)height, BPP = pixel_size * 8, Mode = type, BaseOffset = (uint)dir[0].Offset, }; return new AbmArchive (file, this, dir, image_info); }