public MMAP ProcessCustom(string customfilename, bool mmap) { // Going to set up a memory stream for graphic byte[] custombm = new byte[9216]; byte[] custompal = new byte[1024]; MMAP customMMAP = InitPortrait(); binreader = new BinaryReader(File.Open(customfilename, FileMode.Open)); Int16 checkhda = binreader.ReadInt16(); Int16 checkhdb = binreader.ReadInt16(); // BMP file... if (checkhda == 19778) { // Need temporary holder for bitmap and palette since they need processed. byte[] BMPbm = new byte[9216]; byte[] BMPpal = new byte[1024]; binreader.BaseStream.Position = 54; for (int i = 0; i < 1024; i++) { BMPpal[i] = binreader.ReadByte(); } for (int i = 0; i < 9216; i++) { BMPbm[i] = binreader.ReadByte(); } // Process the bmp file since this is going into the DAT before it is displayed custompal = ConvertPalette(BMPpal, true); custombm = ConvertBitmap(BMPbm); } // DDS file if (checkhda == 17476 && checkhdb == 8275) { // DDS header is 128 bytes binreader.BaseStream.Position = 128; for (int i = 0; i < 9216; i++) { custombm[i] = binreader.ReadByte(); } for (int i = 0; i < 1024; i++) { custompal[i] = binreader.ReadByte(); } } if (checkhda != 19778 && checkhda != 17476 && checkhdb != 8275) { binreader.Close(); return(null); } customMMAP.Bitmaps[0] = custombm; customMMAP.Palettes[0] = custompal; binreader.Close(); return(customMMAP); }
public Filetype() { mmap_data = new MMAP(); compressed_data = new List <byte>(); undefined_data = new List <byte>(); filetype = ""; nullfile = false; changed = false; size = 0; }
public Filetype(TERF terf, MMAP custom) { mmap_data = custom; compressed_data = new List <byte>(); undefined_data = new List <byte>(); filetype = ""; nullfile = false; changed = false; size = this.GetSize(); }
public void Import(int position, TERF terf, MMAP custom) { Filetype user = new Filetype(terf, custom); if (position == -1) { this.DataFiles.Add(user); terf.Dir1.Import(terf, position, false, user.size); terf.Comp.Import(terf, position, false, user.size, 0); } changed = true; }
public Filetype(DAT dat, TERF terf) { mmap_data = new MMAP(); compressed_data = new List <byte>(); undefined_data = new List <byte>(); filetype = ""; nullfile = false; changed = false; needsfixed = false; size = 0; this.Read(dat, terf, false, -1); }
public void ImportCustom(string customfilename, int portnum) { portnum += 1; bool fixcomp = false; custom256 = 1; // Compressed Files if (newcomp.complength > 0) { if (newcomp.complvl[portnum] == 5) { // Need to delete the compfile. Fix comp table. // fix dir1 table customMMAP = new MMAP(); customMMAP = InitPortrait(); // Delete old file newdata.datafiles.RemoveAt(portnum); // Insert new uncompresed MMAP file newdata.datafiles.Insert(portnum, customMMAP); fixcomp = true; } } // Import into current uncompressed. MMAP newportmmap = ProcessCustom(customfilename, true); newdata.datafiles[portnum] = newportmmap; int newsize = GetFileSize(portnum); if (fixcomp) { FixCompTable(portnum, newsize); } if (newdata.datalength > 0) { FixDAT(portnum, newsize); } }
public MMAP InitPortrait() { // Initialize a new MMAP based on Portrait settings MMAP customMMAP = new MMAP(); customMMAP.MMAPFiles = 1; customMMAP.MMAPBitmaps = 1; customMMAP.MMAPPalettes = 1; customMMAP.MMAPUnknown = 0; customMMAP.FileTable_Offset = 10352; customMMAP.PaletteTable_Offset = 9280; customMMAP.FileNames_Offset = 10336; customMMAP.Xinfo.xitableoffset = 0; customMMAP.BM_Table.BitMapWidth.Add(96); customMMAP.BM_Table.BitMapHeight.Add(96); customMMAP.BM_Table.BitMapColor.Add(9); customMMAP.BM_Table.BitMapOffset.Add(0); customMMAP.BM_Table.BitMapSize.Add(9216); customMMAP.HDR_Length = 40; customMMAP.Pal_Table.Palette_Unknown1.Add(1); customMMAP.Pal_Table.Palette_Unknown2.Add(34); customMMAP.Pal_Table.PaletteSize.Add(1024); customMMAP.Pal_Table.PaletteOffset.Add(9312); byte[] name = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; customMMAP.FileNames.Add(name); customMMAP.File_Table.GfxPalettes.Add(1); customMMAP.File_Table.GfxBitmaps.Add(1); customMMAP.File_Table.GfxBitmapOffset.Add(0); customMMAP.File_Table.GfxPaletteOffset.Add(0); byte[] bm = new byte[9216]; byte[] pal = new byte[1024]; customMMAP.Bitmaps.Add(bm); customMMAP.Palettes.Add(pal); return(customMMAP); }
public string ProcessMMAP() { int count = 0; while (count < totalfiles) { newterf.headercheck = 0; if (newdir1.dirlength > 0) { if (newdir1.filelength[count] == 0) { newmmap.nullfilepad = binreader.ReadBytes((int)newterf.terf_offset); ZeroTables(count); } } if (newcomp.complength > 0) { if (newcomp.complvl[count] == 5) { // This is a compressed file. // Read into byte array and be done with it. // Compressed files have variable padding bytes that need to be dealt // with. newmmap.compfile = binreader.ReadBytes((int)newdir1.filelength[count]); ZeroTables(count); //get file padding binreader.ReadBytes(GetPad((int)newterf.filepad, (int)newdir1.filelength[count])); } } // Ok this isn't a compressed or null file, so process it. if (newmmap.compfile == null && newmmap.nullfilepad == null) { newterf.headercheck = binreader.ReadUInt32(); if (newterf.headercheck == newmmap.mmap) { // ok, this is an MMAP so continue with the reading of the file. // Half of this stuff is constants, so skip over them, perhaps add a check // to be sure they aren't messed up later on newmmap.elements = binreader.ReadUInt16(); newmmap.filelist = binreader.ReadUInt16(); newmmap.location = binreader.ReadUInt32(); newmmap.MMAPFiles = binreader.ReadUInt16(); newmmap.MMAPBitmaps = binreader.ReadUInt16(); newmmap.MMAPPalettes = binreader.ReadUInt16(); newmmap.MMAPUnknown = binreader.ReadUInt16(); newmmap.FileTable_Offset = binreader.ReadUInt32(); newmmap.HDR_Length = binreader.ReadUInt32(); newmmap.PaletteTable_Offset = binreader.ReadUInt32(); newmmap.FileNames_Offset = binreader.ReadUInt32(); newmmap.Xinfo.xitableoffset = binreader.ReadUInt32(); // MMAP header is now read in. // Set up a loop to read in the tables int c = 0; while (c < newmmap.MMAPBitmaps) { newmmap.BM_Table.BitMapWidth.Add(binreader.ReadUInt16()); newmmap.BM_Table.BitMapHeight.Add(binreader.ReadUInt16()); newmmap.BM_Table.BitMapColor.Add(binreader.ReadUInt32()); newmmap.BM_Table.BitMapSize.Add(binreader.ReadUInt32()); newmmap.BM_Table.BitMapOffset.Add(binreader.ReadUInt32()); c++; } // BitMap Table complete // Read Padding bytes for BitMap table. Multiple of 32 bytes, plus header // of 40 bytes. These are null bytes so just discard them. binreader.ReadBytes(GetPad(32, (int)(newmmap.MMAPBitmaps * 16 + 40))); //int readpad = (int) ((newmmap.BM_Table.BitMapOffset[0] - (newmmap.MMAPBitmaps*16 + 40))); //binreader.ReadBytes(readpad); // Load in BitMaps to the list of byte arrays c = 0; while (c < newmmap.MMAPBitmaps) { newmmap.Bitmaps.Add(binreader.ReadBytes(Convert.ToInt32(newmmap.BM_Table.BitMapSize[c]))); c++; } // BitMaps are all read in now, continue to palette table c = 0; while (c < newmmap.MMAPPalettes) { newmmap.Pal_Table.Palette_Unknown1.Add(binreader.ReadUInt16()); newmmap.Pal_Table.Palette_Unknown2.Add(binreader.ReadUInt16()); newmmap.Pal_Table.PaletteSize.Add(binreader.ReadUInt32()); newmmap.Pal_Table.PaletteOffset.Add(binreader.ReadUInt32()); c++; } // Read in Palette Padding bytes. Palette Table 12 bytes per entry. // Multiple of 32 bytes again. binreader.ReadBytes(GetPad(32, (int)(newmmap.MMAPPalettes * 12))); // Now read in each set of palettes c = 0; while (c < newmmap.MMAPPalettes) { newmmap.Palettes.Add(binreader.ReadBytes((int)newmmap.Pal_Table.PaletteSize[c])); c++; } // Palettes are all done. // FileNames Listing exists, read 16 bytes per entry for (int s = 0; s < newmmap.MMAPFiles; s++) { newmmap.FileNames.Add(binreader.ReadBytes(16)); } // Filename list is now done. Now read in the filetable c = 0; while (c < newmmap.MMAPFiles) { newmmap.File_Table.GfxPalettes.Add(binreader.ReadUInt16()); newmmap.File_Table.GfxBitmaps.Add(binreader.ReadUInt16()); newmmap.File_Table.GfxBitmapOffset.Add(binreader.ReadUInt32()); newmmap.File_Table.GfxPaletteOffset.Add(binreader.ReadUInt32()); c++; } // File Table is now read in // Need to check for xtra_info as in the face files info if ((int)newmmap.Xinfo.xitableoffset > 0) { newmmap.Xinfo.xilength = binreader.ReadUInt32(); newmmap.Xinfo.xioffset = binreader.ReadUInt32(); newmmap.Xinfo.xibytes = binreader.ReadBytes((int)newmmap.Xinfo.xilength); } // Don't forget to check for file padding. int thislength = 0; thislength += 40 + ((int)newmmap.MMAPBitmaps * 16); thislength += GetPad(32, (int)(newmmap.MMAPBitmaps * 16) + 40); c = 0; while (c < newmmap.MMAPBitmaps) { thislength += newmmap.Bitmaps[c].Length; c++; } thislength += (int)newmmap.MMAPPalettes * 12; thislength += GetPad(32, (int)(newmmap.MMAPPalettes * 12)); c = 0; while (c < newmmap.MMAPPalettes) { thislength += newmmap.Palettes[c].Length; c++; } // Add filenames and filetable bytes thislength += (int)(newmmap.MMAPFiles * 16) + (int)(newmmap.MMAPFiles * 12); if ((int)newmmap.Xinfo.xitableoffset > 0) { thislength += 8 + newmmap.Xinfo.xibytes.Length; } // Finally get any padding from this result if (newterf.filepad > 0) { binreader.ReadBytes(GetPad((int)newterf.filepad, thislength)); } } else { // Ok this isn't a compressed file and it isn't an MMAP file // Need to fix this to load in PLADATA.DAT files etc... // read it into a non standard byte[] and be done // Need to back up 4 bytes because we read in a header check that // wasn't a valid header // TO DO : FIX THIS !!! long current = binreader.BaseStream.Position; binreader.BaseStream.Position = (current - 4); newmmap.non_std_file = binreader.ReadBytes((int)newdir1.filelength[count]); ZeroTables(count); // Now read file pad binreader.ReadBytes(GetPad((int)newterf.filepad, (int)newdir1.filelength[count])); } } // Done reading in data for this MMAP, now add it to the // collection and go to the next one. newdata.datafiles.Add(newmmap); newmmap = new MMAP(); count++; } return(""); }