public void Write(Writer writer, bool SingleFile = false) { int ss = Directory.Length; writer.Write((byte)ss); string str = Directory; for (int i = 0; i < ss; i++) { int s = str[i]; writer.Write((byte)(s ^ (0xFF - ss))); } writer.Write(Address); if (SingleFile) { writer.Close(); } }
public void Write(Writer writer) { writer.Write((byte)SpriteSheets.Count); for (int i = 0; i < SpriteSheets.Count; ++i) { writer.WriteRSDKString(SpriteSheets[i]); } writer.Write((byte)Animations.Count); for (int i = 0; i < Animations.Count; ++i) { Animations[i].Write(writer); } writer.Write((byte)CollisionBoxes.Count); for (int i = 0; i < CollisionBoxes.Count; ++i) { CollisionBoxes[i].Write(writer); } writer.Close(); }
internal void Write(Writer writer) { writer.Write((byte)Layers.Count); writer.Write((byte)HLines.Count); writer.Write((byte)VLines.Count); for (int i = 0; i < HLines.Count; i++) { HLines[i].Write(writer); } for (int i = 0; i < VLines.Count; i++) { VLines[i].Write(writer); } for (int i = 0; i < Layers.Count; i++) { Layers[i].Write(writer); } writer.Close(); }
public void write(Writer writer) { // Too Lazy to do this properly, have 8 layers no matter what writer.Write((byte)8); writer.Write((byte)hScroll.Count); foreach (ScrollInfo hScrollInfo in hScroll) { hScrollInfo.write(writer); } writer.Write((byte)vScroll.Count); foreach (ScrollInfo vScrollInfo in vScroll) { vScrollInfo.write(writer); } foreach (Layer layer in layers) { layer.write(writer); } writer.Close(); }
internal void Write(Writer writer) { writer.Close(); }
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(Writer writer, bool SingleFile = false) { FileName = FileName.Replace('\\', '/'); fileSize = (uint)Filedata.Length; 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; } } } for (int i = 0; i < FileName.Length; i++) { writer.Write((byte)(FileName[i] ^ (0xFF))); } writer.Write((uint)fileSize); writer.Write(outfbuf); } }
public void Write(Writer 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(Writer writer, bool SingleFile = false) { 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 { // Encrypt file decryptKeyZ = ((int)fileSize & 0x1fc) >> 2; decryptKeyIndex2 = (decryptKeyZ % 9) + 1; decryptKeyIndex1 = (decryptKeyZ % decryptKeyIndex2) + 1; decryptKeyIndexZ = 0; int[] outbuf = new int[Filedata.Length]; for (int i = 0; i < (int)fileSize; i++) { outbuf[i] = Filedata[i]; } for (int i = 0; i < (int)fileSize; i++) { outbuf[i] ^= decryptKey1[decryptKeyIndex1++]; if (decryptKeyIndexZ == 1) // swap nibbles { outbuf[i] = (outbuf[i] >> 4) | ((outbuf[i] & 0xf) << 4); } outbuf[i] ^= 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 = new byte[outbuf.Length]; for (int i = 0; i < outbuf.Length; i++) { Filedata[i] = (byte)outbuf[i]; } writer.Write(fileSize); writer.Write(Filedata); } }
internal void Write(Writer writer) { //Checks To Make Sure the Data Is Valid For Saving if (width > 255) { throw new Exception("Cannot save as Type v2. Width in tiles > 255"); } if (height > 255) { throw new Exception("Cannot save as Type v2. Height in tiles > 255"); } int num_of_objects = objects.Count; if (num_of_objects >= MaxObjectCount) { Console.WriteLine("Object Count > Max Objects!"); return; } // Write zone name writer.WriteRSDKString(Title); // Write the five "display" bytes writer.Write(ActiveLayer0); writer.Write(ActiveLayer1); writer.Write(ActiveLayer2); writer.Write(ActiveLayer3); writer.Write(Midpoint); // Write width and height writer.Write((byte)width); writer.Write((byte)height); // Write tile map for (int h = 0; h < height; h++) { for (int w = 0; w < width; w++) { writer.Write((byte)(MapLayout[h][w] >> 8)); writer.Write((byte)(MapLayout[h][w] & 0xff)); } } // Write number of object type names int num_of_objtype_names = objectTypeNames.Count; writer.Write((byte)(num_of_objtype_names)); // Write object type names // Ignore first object type "Type zero", it is not stored. for (int n = 0; n < num_of_objtype_names; n++) { writer.WriteRSDKString(objectTypeNames[n]); } // Write number of objects writer.Write((byte)(num_of_objects >> 8)); writer.Write((byte)(num_of_objects & 0xFF)); objects = objects.OrderBy(o => o.id).ToList(); // Write object data for (int n = 0; n < num_of_objects; n++) { Object obj = objects[n]; obj.Write(writer); } writer.Close(); }
internal void Write(Writer writer) { 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("Images to be converted to GFX format can't be wider than 65535 pixels"); } if (gfxImage.Height > 65535) { throw new Exception("Images to be converted to GFX format can't be higher than 65535 pixels"); } GFXpal = new gfxPalette(); 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; for (int h = 0; h < gfxImage.Height; h++) { for (int w = 0; w < gfxImage.Width; w++) { pixels[pix++] = Get8bppImagePixel(gfxImage, new Point(w, h)); } } // 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.r[i] = gfxImage.Palette.Entries[i].R; GFXpal.g[i] = gfxImage.Palette.Entries[i].G; GFXpal.b[i] = gfxImage.Palette.Entries[i].B; } // Output palette for (int x = 0; x < 255; x++) { writer.Write(GFXpal.r[x]); writer.Write(GFXpal.g[x]); writer.Write(GFXpal.b[x]); } // 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); cnt = 0; } p = pixels[x]; cnt++; } rle_write(writer, p, cnt); // End of GFX file writer.Write((byte)0xFF); writer.Write((byte)0xFF); writer.Close(); }
internal void Write(Writer writer) { //Checks To Make Sure the Data Is Valid For Saving if (this.width > 255) { throw new Exception("Cannot save as Type v1. Width in tiles > 255"); } if (this.height > 255) { throw new Exception("Cannot save as Type v1. Height in tiles > 255"); } int num_of_objects = objects.Count; if (num_of_objects > 65535) { throw new Exception("Cannot save as Type v1. Number of objects > 65535"); } for (int n = 0; n < num_of_objects; n++) { Object obj = objects[n]; int obj_type = obj.getType(); int obj_subtype = obj.getSubtype(); int obj_xPos = obj.getXPos(); int obj_yPos = obj.getYPos(); if (obj_type > 255) { throw new Exception("Cannot save as Type v1. Object type > 255"); } if (obj_subtype > 255) { throw new Exception("Cannot save as Type v1. Object subtype > 255"); } if (obj_xPos < -32768 || obj_xPos > 32767) { throw new Exception("Cannot save as Type v1. Object X Position can't fit in 16-bits"); } if (obj_yPos < -32768 || obj_yPos > 32767) { throw new Exception("Cannot save as Type v1. Object Y Position can't fit in 16-bits"); } } // Write zone name writer.WriteRSDKString(Title); // Write the five "display" bytes we kept writer.Write(displayBytes); // Write width and height writer.Write((byte)this.width); writer.Write((byte)this.height); // Write tile map for (int h = 0; h < this.height; h++) { for (int w = 0; w < this.width; w++) { writer.Write((byte)(MapLayout[h][w] >> 8)); writer.Write((byte)(MapLayout[h][w] & 0xff)); } } // Write number of object type names int num_of_objtype_names = this.objectTypeNames.Count; writer.Write((byte)(num_of_objtype_names)); // Write object type names // Ignore first object type "Type zero", it is not stored. for (int n = 0; n < num_of_objtype_names; n++) { writer.WriteRSDKString(objectTypeNames[n]); } // Write number of objects writer.Write((byte)(num_of_objects >> 8)); writer.Write((byte)(num_of_objects & 0xFF)); // Write object data for (int n = 0; n < num_of_objects; n++) { Object obj = objects[n]; int obj_type = obj.type; int obj_subtype = obj.subtype; int obj_xPos = obj.xPos; int obj_yPos = obj.yPos; writer.Write((byte)(obj_type)); writer.Write((byte)(obj_subtype)); writer.Write((byte)(obj_xPos >> 8)); writer.Write((byte)(obj_xPos & 0xFF)); writer.Write((byte)(obj_yPos >> 8)); writer.Write((byte)(obj_yPos & 0xFF)); } writer.Close(); }
public void write(Writer writer, bool skipHeader = false, bool useLocal = false) { #region Header // [GIF HEADER] if (!skipHeader) { writer.Write("GIF".ToCharArray()); // File type writer.Write("89a".ToCharArray()); // File Version writer.Write(width); writer.Write(height); if (useLocal) { writer.Write((byte)((1 << 7) | (6 << 4) | 6)); // 1 == hasColours, 6 == paletteSize of 128, 6 == 7bpp } else { writer.Write((byte)((1 << 7) | (7 << 4) | 7)); // 1 == hasColours, 7 == paletteSize of 256, 7 == 8bpp } writer.Write((byte)0); writer.Write((byte)0); } // [GLOBAL PALETTE] for (int c = 0; c < (useLocal ? 0x80 : 0x100); ++c) { writer.Write(palette[c].R); writer.Write(palette[c].G); writer.Write(palette[c].B); } #endregion #region Extension Blocks // [EXTENSION BLOCKS] #endregion #region Image Descriptor Block // [IMAGE DESCRIPTOR HEADER] writer.Write(','); writer.Write((ushort)0); writer.Write((ushort)0); writer.Write((ushort)width); writer.Write((ushort)height); if (useLocal) { writer.Write((byte)((1 << 7) | (0 << 6) | 6)); // 1 == useLocal, 0 == no interlacing, 6 == 7bpp } else { writer.Write((byte)((0 << 7) | (0 << 6) | 0)); // 0 == noLocal, 0 == no interlacing, no local palette, so we dont care } // [LOCAL PALETTE] if (useLocal) { for (int c = 0x80; c < 0x100; ++c) { writer.Write(palette[c].R); writer.Write(palette[c].G); writer.Write(palette[c].B); } } // [IMAGE DATA] writePictureData(width, height, false, useLocal ? (byte)7 : (byte)8, writer); // [BLOCK END MARKER] writer.Write(';'); // ';' used for image descriptor, 0 would be used for other blocks #endregion writer.Close(); }
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(); }