Exemple #1
0
            public void Write(Writer writer, bool SingleFile = false)
            {
                bool DontFlip = false;

                FileName = FileName.Replace('\\', '/');
                writer.Write(FileName);

                string ext = System.IO.Path.GetExtension(FileName);

                if (ext == ".ogg" || ext == ".wav")
                {
                    DontFlip  = true;
                    encrypted = false;
                }
                else
                {
                    encrypted = true;
                    DontFlip  = false;
                }

                Console.WriteLine(FileName + " Test " + DontFlip);

                if (DontFlip)
                {
                    writer.Write((uint)fileSize);
                    writer.Write(Filedata);
                }
                else if (!DontFlip)
                {
                    writer.Write((uint)fileSize);
                    byte[] fdata = new byte[Filedata.Length];
                    for (int i = 0; i < Filedata.Length; i++)
                    {
                        fdata[i] = (byte)~Filedata[i];
                    }
                    writer.Write(fdata);
                }
                if (SingleFile)
                {
                    writer.Close();
                }
            }
        public void write(Writer writer, bool dcVer = false)
        {
            writer.Write(unknown); //No idea what this is
            writer.Write((byte)playerType);
            writer.Write((byte)animations.Count);

            // SpriteSheets
            for (int s = 0; s < (dcVer ? 2 : 3); ++s)
            {
                writer.writeRSDKString(spriteSheets[s]);
            }

            // Animations
            foreach (AnimationEntry anim in animations)
            {
                anim.write(writer);
            }

            writer.Close();
        }
        public void write(Writer writer)
        {
            // Palettes
            stagePalette.write(writer);

            // SpriteSheets
            writer.Write((byte)spriteSheets.Count);
            foreach (string sheet in spriteSheets)
            {
                writer.writeRSDKString(sheet);
            }

            // Objects
            writer.Write((byte)objects.Count);
            foreach (ObjectInfo info in objects)
            {
                writer.Write(info.script);
            }

            foreach (ObjectInfo info in objects)
            {
                writer.Write((byte)info.sheetID);
            }

            // SoundFX
            writer.Write((byte)soundFX.Count);
            foreach (string path in soundFX)
            {
                writer.writeRSDKString(path);
            }

            // Music
            writer.Write((byte)musicTracks.Count);
            foreach (string track in musicTracks)
            {
                writer.writeRSDKString(track);
            }

            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();
        }
Exemple #5
0
        internal void Write(Writer writer)
        {
            writer.Write(layerCount);
            writer.Write((byte)Lines.Count);

            for (int lc = 0; lc < Lines.Count; lc++)
            {
                Lines[lc].Write(writer);
            }

            writer.Write(Unknown1);

            for (int i = 0; i < Unknown1; i++)
            {
                UnknownVals[i].Write(writer);
            }

            for (int i = 0; i < layerCount; i++) //Read BG Layers
            {
                Layers[i].Write(writer);
            }

            writer.Close();
        }
Exemple #6
0
 internal void Write(Writer writer)
 {
     writer.Close();
 }
Exemple #7
0
        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 >= 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)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));

            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();
        }
Exemple #8
0
        internal void Write(Writer writer)
        {
            //Checks To make sure that the file can be saved correctly

            int num_of_objects = objects.Count;

            if (num_of_objects > 65535)
            {
                throw new Exception("Cannot save as Retro-Sonic map. 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 Retro-Sonic map. Object type > 255");
                }

                if (obj_subtype > 255)
                {
                    throw new Exception("Cannot save as Retro-Sonic map. Object subtype > 255");
                }

                if (obj_xPos < -32768 || obj_xPos > 32767)
                {
                    throw new Exception("Cannot save as Retro-Sonic. Object X Position can't fit in 16-bits");
                }

                if (obj_yPos < -32768 || obj_yPos > 32767)
                {
                    throw new Exception("Cannot save as Retro-Sonic. Object Y Position can't fit in 16-bits");
                }
            }

            // Save zone name
            writer.WriteRSDKString(Title);

            // Write the Stage Init Data
            writer.Write(Music);
            writer.Write(Background);
            writer.Write((byte)(PlayerXpos >> 8));
            writer.Write((byte)(PlayerXpos & 0xFF));
            writer.Write((byte)(PlayerYPos >> 8));
            writer.Write((byte)(PlayerYPos & 0xFF));

            // 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();
        }
Exemple #9
0
        internal void Write(Writer writer)
        {
            //Checks To make sure that the file can be saved correctly

            if (width >= 256)
            {
                throw new Exception("Cannot save as Retro-Sonic map. Level width in tiles > 255.");
            }

            if (height >= 256)
            {
                throw new Exception("Cannot save as Retro-Sonic map. Level height in tiles > 255.");
            }

            int num_of_objects = objects.Count;

            if (num_of_objects > 65535)
            {
                throw new Exception("Cannot save as Retro-Sonic map. 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 Retro-Sonic map. Object type > 255");
                }

                if (obj_subtype > 255)
                {
                    throw new Exception("Cannot save as Retro-Sonic map. Object subtype > 255");
                }

                if (obj_xPos < -32768 || obj_xPos > 32767)
                {
                    throw new Exception("Cannot save as Retro-Sonic. Object X Position can't fit in 16-bits");
                }

                if (obj_yPos < -32768 || obj_yPos > 32767)
                {
                    throw new Exception("Cannot save as Retro-Sonic. Object Y Position can't fit in 16-bits");
                }
            }

            // Separate path components
            String dirname  = Path.GetDirectoryName(writer.GetFilename());
            String basename = "\\" + Path.GetFileNameWithoutExtension(writer.GetFilename());

            String itmPath = dirname + basename + ".itm";

            // Create item file
            Writer ITMwriter = new Writer(itmPath);

            // Save width and height
            writer.Write((byte)width);
            writer.Write((byte)height);

            // Save map data
            for (int y = 0; y < height; y++)
            {
                for (int x = 0; x < width; x++)
                {
                    writer.Write((byte)MapLayout[y][x]);
                }
            }

            // Close map file
            writer.Close();

            // Save zone name
            ITMwriter.WriteRSDKString(Title);

            // Write the Stage Init Data
            ITMwriter.Write(Music);
            ITMwriter.Write(Background);
            ITMwriter.Write((byte)(PlayerXpos >> 8));
            ITMwriter.Write((byte)(PlayerXpos & 0xFF));
            ITMwriter.Write((byte)(PlayerYPos >> 8));
            ITMwriter.Write((byte)(PlayerYPos & 0xFF));

            // Write number of objects
            ITMwriter.Write((byte)(num_of_objects >> 8));
            ITMwriter.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;

                ITMwriter.Write((byte)obj_type);
                ITMwriter.Write((byte)obj_subtype);

                ITMwriter.Write((byte)(obj_xPos >> 8));
                ITMwriter.Write((byte)(obj_xPos & 0xFF));

                ITMwriter.Write((byte)(obj_yPos >> 8));
                ITMwriter.Write((byte)(obj_yPos & 0xFF));
            }
            ITMwriter.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;

            // var orderedFiles = files.OrderBy(f => f.directoryID).ToList();

            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();
        }
Exemple #11
0
        public void write(Writer writer)
        {
            foreach (ScriptSub sub in subs)
            {
                // Script Code
                writer.Write((byte)(sub.scriptCodeLength >> 8));
                writer.Write((byte)(sub.scriptCodeLength & 0xFF));

                foreach (OpcodeInfo opInfo in sub.scriptCode)
                {
                    writer.Write(opInfo.opcode);

                    int paramID = 0;
                    foreach (ParamInfo param in opInfo.parameters)
                    {
                        writer.Write((byte)(param.isVariable ? 1 : 0));
                        if (param.isVariable)
                        {
                            writer.Write((byte)param.value);

                            if (param.arrayIndex < 0)
                            {
                                byte value = (byte)-param.value;
                                writer.Write((byte)(value + 0x80));
                            }
                            else
                            {
                                writer.Write((byte)param.arrayIndex);
                            }
                        }
                        else
                        {
                            // Gross switch hack, but its set using jumpTable, not here
                            if (opInfo.opcode == 0x30 && paramID == 1)
                            {
                                writer.Write((byte)(0 >> 8));
                                writer.Write((byte)(0 & 0xFF));
                            }
                            else
                            {
                                if (param.value < 0)
                                {
                                    int   value = -param.value;
                                    sbyte byte1 = (sbyte)(value >> 8);
                                    writer.Write((byte)(byte1 + 0x80));
                                    writer.Write((byte)(value & 0xFF));
                                }
                                else
                                {
                                    writer.Write((byte)(param.value >> 8));
                                    writer.Write((byte)(param.value & 0xFF));
                                }
                            }
                        }

                        ++paramID;
                    }
                }
                writer.Write(0xFFFFFFFF);

                // Unknown
                writer.Write((byte)(0 >> 8));
                writer.Write((byte)(sub.blankLines.Count & 0xFF));
                foreach (int lineID in sub.blankLines)
                {
                    // a line to put a blank space on
                    writer.Write((byte)(lineID >> 8));
                    writer.Write((byte)(lineID & 0xFF));
                }

                // Labels
                writer.Write((byte)(0 >> 8));
                writer.Write((byte)(sub.labels.Count & 0xFF));
                foreach (LabelInfo label in sub.labels)
                {
                    // Where the label should jump to
                    writer.Write((byte)(label.scriptCodePos >> 8));
                    writer.Write((byte)(label.scriptCodePos & 0xFF));

                    // the id of the label
                    writer.Write((byte)(label.id >> 8));
                    writer.Write((byte)(label.id & 0xFF));

                    // the line ID of the label
                    writer.Write((byte)(label.lineID >> 8));
                    writer.Write((byte)(label.lineID & 0xFF));
                }

                // JumpTable (switch cases)
                writer.Write((byte)(0 >> 8));
                writer.Write((byte)(sub.jumpTable.Count & 0xFF));
                foreach (SwitchInfo switchStatement in sub.jumpTable)
                {
                    // the script code pos of the corresponding switch function call
                    writer.Write((byte)(switchStatement.scriptCodePos >> 8));
                    writer.Write((byte)(switchStatement.scriptCodePos & 0xFF));

                    // How many cases the switch statement has
                    writer.Write((byte)(switchStatement.cases.Count >> 8));
                    writer.Write((byte)(switchStatement.cases.Count & 0xFF));

                    // the scriptCodePos to jump to on default cases
                    writer.Write((byte)(switchStatement.defaultScriptCodePos >> 8));
                    writer.Write((byte)(switchStatement.defaultScriptCodePos & 0xFF));

                    // the line ID of the default case
                    writer.Write((byte)(switchStatement.defaultCaseLineID >> 8));
                    writer.Write((byte)(switchStatement.defaultCaseLineID & 0xFF));

                    // the scriptCodePos to jump to on end switch
                    writer.Write((byte)(switchStatement.endScriptCodePos >> 8));
                    writer.Write((byte)(switchStatement.endScriptCodePos & 0xFF));

                    foreach (SwitchCaseInfo caseInfo in switchStatement.cases)
                    {
                        // Where to set the scriptCodePos to
                        writer.Write((byte)(caseInfo.scriptCodePos >> 8));
                        writer.Write((byte)(caseInfo.scriptCodePos & 0xFF));

                        // Case Number
                        writer.Write((byte)(caseInfo.caseNum >> 8));
                        writer.Write((byte)(caseInfo.caseNum & 0xFF));

                        // the line ID of the switch case
                        writer.Write((byte)(caseInfo.lineID >> 8));
                        writer.Write((byte)(caseInfo.lineID & 0xFF));
                    }
                }
            }
            writer.Close();
        }
Exemple #12
0
        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();
        }
Exemple #13
0
        internal void Write(Writer writer, bool dcGFX)
        {
            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));
                }
            }

            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.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, 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();
        }