public void Write(System.IO.Stream stream) { using (Writer writer = new Writer(stream)) this.Write(writer); }
public void Write(Writer writer) { int DirHeaderSize = 0; writer.Write(DirHeaderSize); writer.Write((ushort)Directories.Count); for (int i = 0; i < Directories.Count; i++) { Directories[i].Write(writer); } DirHeaderSize = (int)writer.BaseStream.Position; var orderedFiles = Files.OrderBy(f => f.DirID).ToList(); int Dir = 0; Directories[Dir].Address = 0; for (int i = 0; i < Files.Count; i++) { if (Files[i].DirID == Dir) { Files[i].Write(writer); } else { Dir++; Directories[Dir].Address = (int)writer.BaseStream.Position - DirHeaderSize; Files[i].Write(writer); } } writer.BaseStream.Position = 0; writer.Write(DirHeaderSize); writer.Write((ushort)Directories.Count); for (int i = 0; i < Directories.Count; i++) { Directories[i].Write(writer); } Dir = 0; for (int i = 0; i < Files.Count; i++) { if (Files[i].DirID == Dir) { Files[i].Write(writer); } else { Dir++; Files[i].Write(writer); } } writer.Close(); }
public void Write(string filename) { using (Writer writer = new Writer(filename)) this.Write(writer); }
internal void Write(Writer writer) { writer.Close(); }
public void Write(Writer writer, bool SingleFile = false) { FileName = FileName.Replace('\\', '/'); int ss = FileName.Length; writer.Write((byte)ss); string str = FileName; fileSize = (uint)Filedata.Length; for (int i = 0; i < ss; i++) { int s = str[i]; writer.Write((byte)(s ^ (0xFF))); } if (SingleFile) { writer.Write(fileSize); writer.Write(Filedata); writer.Close(); } else { byte[] outfbuf = Filedata; // Encrypt file decryptKeyZ = (byte)(fileSize & 0x1fc) >> 2; decryptKeyIndex2 = (decryptKeyZ % 9) + 1; decryptKeyIndex1 = (decryptKeyZ % decryptKeyIndex2) + 1; decryptKeyIndexZ = 0; for (ulong i = 0; i < fileSize; i++) { outfbuf[i] ^= (byte)decryptKey1[decryptKeyIndex1++]; if (decryptKeyIndexZ == 1) // swap nibbles { outfbuf[i] = (byte)((outfbuf[i] >> 4) | ((outfbuf[i] & 0xf) << 4)); } outfbuf[i] ^= (byte)(decryptKey2[decryptKeyIndex2++] ^ decryptKeyZ); if ((decryptKeyIndex1 <= 19) || (decryptKeyIndex2 <= 11)) { if (decryptKeyIndex1 > 19) { decryptKeyIndex1 = 1; decryptKeyIndexZ ^= 1; } if (decryptKeyIndex2 > 11) { decryptKeyIndex2 = 1; decryptKeyIndexZ ^= 1; } } else { decryptKeyZ++; decryptKeyZ &= 0x7F; if (decryptKeyIndexZ != 0) { decryptKeyIndex1 = (decryptKeyZ % 12) + 6; decryptKeyIndex2 = (decryptKeyZ % 5) + 4; decryptKeyIndexZ = 0; } else { decryptKeyIndexZ = 1; decryptKeyIndex1 = (decryptKeyZ % 15) + 3; decryptKeyIndex2 = (decryptKeyZ % 7) + 1; } } } Filedata = outfbuf; writer.Write((uint)fileSize); writer.Write(Filedata); } }
public void Write(Writer writer) { writer.WriteRSDKString(Name); writer.Write(Value); }
public void Write(System.IO.Stream reader) { using (Writer writer = new Writer(reader)) this.Write(writer); }
public void write(Writer writer) { writer.writeRSDKString(directory); writer.Write(startOffset); }
public void write(Writer writer) { // Initial File Write int headerSize = 0; writer.Write(headerSize); writer.Write((byte)directories.Count); foreach (DirInfo dir in directories) { dir.write(writer); } headerSize = (int)writer.BaseStream.Position; int dirID = 0; directories[dirID].startOffset = 0; foreach (FileInfo file in files) { if (file.directoryID == dirID) { file.write(writer); } else { dirID++; directories[dirID].startOffset = (int)writer.BaseStream.Position - headerSize; file.write(writer); } } // Real File write writer.seek(0, System.IO.SeekOrigin.Begin); writer.Write(headerSize); writer.Write((byte)directories.Count); foreach (DirInfo dir in directories) { dir.write(writer); } dirID = 0; foreach (FileInfo file in files) { if (file.directoryID == dirID) { file.write(writer); } else { dirID++; file.write(writer); } } writer.Close(); }
public void Write(Writer writer, bool dcGFX = false, bool raw = false) { if (gfxImage == null) { throw new Exception("Image is NULL"); } if (gfxImage.Palette == null || gfxImage.Palette.Entries.Length == 0) { throw new Exception("Only indexed images can be converted to GFX format."); } if (gfxImage.Width > 65535) { throw new Exception("GFX Images can't be wider than 65535 pixels"); } if (gfxImage.Height > 65535) { throw new Exception("GFX Images can't be higher than 65535 pixels"); } int num_pixels = gfxImage.Width * gfxImage.Height; int[] pixels = new int[num_pixels]; //Pallete Indexes // Images can't contain index 255 for (int x = 0; x < num_pixels; x++) { if (pixels[x] == 255) { throw new Exception("Images to be converted to GFX format can't contain index 255."); } } int pix = 0; if (raw) //get data from "data" array { for (int h = 0; h < height; h++) { for (int w = 0; w < width; w++) { pixels[pix] = data[pix]; pix++; } } } else //Get Data from Bitmap Class { for (int h = 0; h < gfxImage.Height; h++) { for (int w = 0; w < gfxImage.Width; w++) { pixels[pix++] = Get8bppImagePixel(gfxImage, new Point(w, h)); } } } if (dcGFX) { byte z = 0; writer.Write(z); } // Output width and height writer.Write((byte)(gfxImage.Width >> 8)); writer.Write((byte)(gfxImage.Width & 0xff)); writer.Write((byte)(gfxImage.Height >> 8)); writer.Write((byte)(gfxImage.Height & 0xff)); for (int i = 0; i < gfxImage.Palette.Entries.Length; i++) { GFXpal[i].R = gfxImage.Palette.Entries[i].R; GFXpal[i].G = gfxImage.Palette.Entries[i].G; GFXpal[i].B = gfxImage.Palette.Entries[i].B; } // Output palette for (int x = 0; x < 255; x++) { writer.Write(GFXpal[x].R); writer.Write(GFXpal[x].G); writer.Write(GFXpal[x].B); } // Output data int p = 0; int cnt = 0; for (int x = 0; x < num_pixels; x++) { if (pixels[x] != p && x > 0) { rle_write(writer, p, cnt, dcGFX); cnt = 0; } p = pixels[x]; cnt++; } rle_write(writer, p, cnt, dcGFX); // End of GFX file writer.Write((byte)0xFF); writer.Write((byte)0xFF); writer.Close(); }
public void Write(System.IO.Stream stream, bool dcGFX = false) { using (Writer writer = new Writer(stream)) this.Write(writer, dcGFX); }
public void Write(string filename, bool dcGFX = false) { using (Writer writer = new Writer(filename)) this.Write(writer, dcGFX); }