Ejemplo n.º 1
0
        public static Bitmap Get_Image(Bank bank, uint blockSize, ImageBase img, PaletteBase pal, int max_width, int max_height,
            bool draw_grid, bool draw_cells, bool draw_numbers, bool trans, bool image, int currOAM = -1,
            int zoom = 1, int[] index = null)
        {
            Size size = new Size(max_width * zoom, max_height * zoom);
            Bitmap bank_img = new Bitmap(size.Width, size.Height);
            Graphics graphic = Graphics.FromImage(bank_img);

            if (bank.oams.Length == 0)
            {
                graphic.DrawString("No OAM", SystemFonts.CaptionFont, Brushes.Black, new PointF(max_width / 2, max_height / 2));
                return bank_img;
            }

            if (draw_grid)
            {
                for (int i = (0 - size.Width); i < size.Width; i += 8)
                {
                    graphic.DrawLine(Pens.LightBlue, (i + size.Width / 2) * zoom, 0, (i + size.Width / 2) * zoom, size.Height * zoom);
                    graphic.DrawLine(Pens.LightBlue, 0, (i + size.Height / 2) * zoom, size.Width * zoom, (i + size.Height / 2) * zoom);
                }
                graphic.DrawLine(Pens.Blue, (max_width / 2) * zoom, 0, (max_width / 2) * zoom, max_height * zoom);
                graphic.DrawLine(Pens.Blue, 0, (max_height / 2) * zoom, max_width * zoom, (max_height / 2) * zoom);
            }

            Image cell;
            for (int i = 0; i < bank.oams.Length; i++)
            {
                bool draw = false;
                if (index == null)
                    draw = true;
                else
                    for (int k = 0; k < index.Length; k++)
                        if (index[k] == i)
                            draw = true;
                if (!draw)
                    continue;

                if (bank.oams[i].width == 0x00 || bank.oams[i].height == 0x00)
                    continue;

                uint tileOffset = bank.oams[i].obj2.tileOffset;
                tileOffset = (uint)(tileOffset << (byte)blockSize);

                if (image)
                {
                    ImageBase cell_img = new TestImage();
                    cell_img.Set_Tiles((byte[])img.Tiles.Clone(), bank.oams[i].width, bank.oams[i].height, img.FormatColor,
                                       img.FormTile, false);
                    cell_img.StartByte = (int)(tileOffset * 0x20 + bank.data_offset);

                    byte num_pal = bank.oams[i].obj2.index_palette;
                    if (num_pal >= pal.NumberOfPalettes)
                        num_pal = 0;
                    for (int j = 0; j < cell_img.TilesPalette.Length; j++)
                        cell_img.TilesPalette[j] = num_pal;

                    cell = cell_img.Get_Image(pal);
                    //else
                    //{
                    //    tileOffset /= (blockSize / 2);
                    //    int imageWidth = img.Width;
                    //    int imageHeight = img.Height;

                    //    int posX = (int)(tileOffset % imageWidth);
                    //    int posY = (int)(tileOffset / imageWidth);

                    //    if (img.ColorFormat == ColorFormat.colors16)
                    //        posY *= (int)blockSize * 2;
                    //    else
                    //        posY *= (int)blockSize;
                    //    if (posY >= imageHeight)
                    //        posY = posY % imageHeight;

                    //    cells[i] = ((Bitmap)img.Get_Image(pal)).Clone(new Rectangle(posX * zoom, posY * zoom, bank.oams[i].width * zoom, bank.oams[i].height * zoom),
                    //                                                System.Drawing.Imaging.PixelFormat.DontCare);
                    //}

                    #region Flip
                    if (bank.oams[i].obj1.flipX == 1 && bank.oams[i].obj1.flipY == 1)
                        cell.RotateFlip(RotateFlipType.RotateNoneFlipXY);
                    else if (bank.oams[i].obj1.flipX == 1)
                        cell.RotateFlip(RotateFlipType.RotateNoneFlipX);
                    else if (bank.oams[i].obj1.flipY == 1)
                        cell.RotateFlip(RotateFlipType.RotateNoneFlipY);
                    #endregion

                    if (trans)
                        ((Bitmap)cell).MakeTransparent(pal.Palette[num_pal][0]);

                    graphic.DrawImageUnscaled(cell, size.Width / 2 + bank.oams[i].obj1.xOffset * zoom, size.Height / 2 + bank.oams[i].obj0.yOffset * zoom);
                }

                if (draw_cells)
                    graphic.DrawRectangle(Pens.Black, size.Width / 2 + bank.oams[i].obj1.xOffset * zoom, size.Height / 2 + bank.oams[i].obj0.yOffset * zoom,
                        bank.oams[i].width * zoom, bank.oams[i].height * zoom);
                if (i == currOAM)
                    graphic.DrawRectangle(new Pen(Color.Red, 3), size.Width / 2 + bank.oams[i].obj1.xOffset * zoom, size.Height / 2 + bank.oams[i].obj0.yOffset * zoom,
                        bank.oams[i].width * zoom, bank.oams[i].height * zoom);
                if (draw_numbers)
                    graphic.DrawString(bank.oams[i].num_cell.ToString(), SystemFonts.CaptionFont, Brushes.Black, size.Width / 2 + bank.oams[i].obj1.xOffset * zoom,
                        size.Height / 2 + bank.oams[i].obj0.yOffset * zoom);
            }

            return bank_img;
        }
Ejemplo n.º 2
0
Archivo: Cell.cs Proyecto: MetLob/tinke
        private void Read(string file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));

            if (br.ReadUInt32() != MagicStamp)
            {
                throw new InvalidDataException();
            }

            uint numSprites = br.ReadUInt32();
            uint dataOffset = br.ReadUInt32();
            int dataLength = br.ReadInt32();
            uint unkOffset = br.ReadUInt32();

            Bank[] sprites = new Bank[numSprites];
            for (int i = 0; i < numSprites; i++)
            {
                br.BaseStream.Position = HeaderSize + i * BankHeaderSize;
                sprites[i] = new Bank();

                ushort unk1 = br.ReadUInt16();
                byte numOams = br.ReadByte();
                byte unk2 = br.ReadByte();
                short yBasePos = br.ReadInt16();
                short xBasePos = br.ReadInt16();
                ushort width = br.ReadUInt16();
                ushort height = br.ReadUInt16();
                uint oamOffset = br.ReadUInt32();
                uint unk7 = br.ReadUInt32();
                uint baseOffset = br.ReadUInt32();

                sprites[i].oams = new OAM[numOams];
                br.BaseStream.Position = oamOffset;
                for (int j = 0; j < numOams; j++)
                {
                    ushort obj0 = br.ReadUInt16();
                    ushort obj1 = br.ReadUInt16();
                    short yPos = br.ReadInt16();
                    short xPos = br.ReadInt16();
                    ushort unkOam3 = br.ReadUInt16();
                    ushort tileOffset = br.ReadUInt16();
                    uint unkOam4 = br.ReadUInt32();

                    sprites[i].oams[j] = Actions.OAMInfo(obj0, obj1, 0);
                    sprites[i].oams[j].obj0.yOffset = yPos + sprites[i].oams[j].obj0.yOffset - (int)(sprites[i].oams[j].height * 1.525);
                    sprites[i].oams[j].obj1.xOffset = xPos + sprites[i].oams[j].obj1.xOffset - (int)(sprites[i].oams[j].width * 1.525);
                    sprites[i].oams[j].obj2.tileOffset = tileOffset;
                    sprites[i].oams[j].num_cell = (ushort)j;
                }
            }

            this.Sprite = new GameSprite();
            this.Sprite.Sprite = new RawSprite(sprites, 0x20);

            ColorFormat depth = ColorFormat.colors16;
            if (sprites.Length > 0 && sprites[0].oams.Length > 0)
            {
                depth = (sprites[0].oams[0].obj0.depth == 0) ? ColorFormat.colors16 : ColorFormat.colors256;
            }
            int palSize = (depth == ColorFormat.colors16) ? 0x20 : 0x200;

            // Get the palette
            br.BaseStream.Position = dataOffset;
            this.Sprite.Palette = new RawPalette(
                Actions.BGR555ToColor(br.ReadBytes(palSize)),
                false,
                depth,
                this.Name);

            // Get the image data
            br.BaseStream.Position = dataOffset;
            byte[] imageData = br.ReadBytes(dataLength);
            this.Sprite.Image = new RawImage(
                imageData,
                TileForm.Lineal,
                depth,
                0x100,
                imageData.Length / 0x100 * ((depth == ColorFormat.colors16) ? 2 : 1),
                false,
                this.Name);

            br.Close();
            br = null;
        }
Ejemplo n.º 3
0
 public RawSprite(Bank[] banks, uint blocksize, bool editable = false)
 {
     Set_Banks(banks, blocksize, editable);
 }
Ejemplo n.º 4
0
 public RawSprite(OAM[] oams, uint blocksize, bool editable = false)
 {
     Bank bank = new Bank();
     bank.name = "Bank 1";
     bank.oams = oams;
     Set_Banks(new Bank[] { bank }, blocksize, editable);
 }
Ejemplo n.º 5
0
 public Image Get_Image(ImageBase image, PaletteBase pal, Bank bank, int width, int height,
     bool grid, bool cell, bool number, bool trans, bool img, int currOAM)
 {
     return Actions.Get_Image(bank, block_size, image, pal, width, height,
                              grid, cell, number, trans, img, currOAM);
 }
Ejemplo n.º 6
0
        public void Set_Banks(Bank[] banks, uint block_size, bool editable)
        {
            this.banks = banks;
            this.block_size = block_size;
            this.canEdit = editable;
            loaded = true;

            // Sort the cell using the priority value
            for (int b = 0; b < banks.Length; b++)
            {
                List<OAM> cells = new List<OAM>();
                cells.AddRange(banks[b].oams);
                cells.Sort(Actions.Comparision_OAM);
                banks[b].oams = cells.ToArray();
            }
        }
Ejemplo n.º 7
0
        public override void Read(string file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));

            info = new SIR0_Info();

            PaletteBase palette;
            ImageBase   image;

            Ekona.Images.Bank bank;

            // Read header
            char[] file_id = br.ReadChars(4);
            uint   offset1 = br.ReadUInt32();
            uint   offset2 = br.ReadUInt32();
            uint   unknown = br.ReadUInt32();
            String name    = "";

            do
            {
                byte c = br.ReadByte();
                if (c == 0xAA)
                {
                    c = 0x00;
                }
                name += (char)c;
            } while (name[name.Length - 1] != '\x0');

            // Read info section
            // Info 1
            br.BaseStream.Position  = offset1;
            info.info1              = new SIR0_Info.Info1();
            info.info1.constant     = br.ReadUInt32();
            info.info1.reserved     = br.ReadBytes(0x3C);
            info.info1.info3_offset = br.ReadUInt32();
            info.info1.reserved2    = br.ReadBytes((int)(offset2 - offset1));
            // Info 2
            br.BaseStream.Position = offset2;
            info.info2             = new SIR0_Info.Info2();
            info.info2.unknown     = br.ReadBytes(0x10);
            // Info 3
            br.BaseStream.Position    = info.info1.info3_offset;
            info.info3                = new SIR0_Info.Info3();
            info.info3.tile_size      = br.ReadUInt32();
            info.info3.unknown1       = br.ReadUInt32();
            info.info3.unknown2       = br.ReadUInt32();
            info.info3.unknown3       = br.ReadUInt32();
            info.info3.unknown4       = br.ReadUInt32();
            info.info3.palette_offset = br.ReadUInt32();
            info.info3.tile_offset    = br.ReadUInt32();
            info.info3.cell_offset    = br.ReadUInt32();
            info.info3.unknown5       = br.ReadUInt32();
            info.info3.reserved       = br.ReadBytes(0x3C);

            // Read palette
            br.BaseStream.Position = info.info3.palette_offset;
            Color[][] colors = new Color[1][];
            colors[0] = Actions.BGR555ToColor(br.ReadBytes(0x200));
            palette   = new RawPalette(colors, false, ColorFormat.colors256, "");

            // Read tiles
            br.BaseStream.Position = info.info3.tile_offset;
            byte[] tiles = new byte[info.info3.tile_size];
            tiles = br.ReadBytes((int)info.info3.tile_size);
            image = new RawImage(tiles, TileForm.Lineal, ColorFormat.colors256, 0x40,
                                 (int)(info.info3.tile_size / 0x40), false, "");

            // Read cell info
            uint bank_size;

            if (info.info3.unknown5 != 0x00)
            {
                bank_size = info.info3.unknown5 - info.info3.cell_offset - 0x06;
            }
            else
            {
                bank_size = info.info1.info3_offset - info.info3.cell_offset - 0x06;
            }

            br.BaseStream.Position = info.info3.cell_offset;
            bank      = new Ekona.Images.Bank();
            bank.oams = new OAM[bank_size / 0x0A];
            for (int i = 0; i < bank.oams.Length; i++)
            {
                bank.oams[i].width           = br.ReadUInt16();
                bank.oams[i].height          = br.ReadUInt16();
                bank.oams[i].obj1.xOffset    = br.ReadUInt16() - 0x80;
                bank.oams[i].obj0.yOffset    = br.ReadUInt16() - 0x80;
                bank.oams[i].obj2.tileOffset = (uint)(br.ReadUInt16() / 0x20);
                bank.oams[i].num_cell        = (ushort)i;
            }
            Set_Banks(new Ekona.Images.Bank[] { bank }, 0, false);
            br.Close();

            pluginHost.Set_Palette(palette);
            pluginHost.Set_Image(image);
            pluginHost.Set_Sprite(this);
        }
Ejemplo n.º 8
0
Archivo: OBJS.cs Proyecto: MetLob/tinke
        public override void Read(string file)
        {
            // It's compressed
            pluginHost.Decompress(file);
            string dec_file;
            sFolder dec_folder = pluginHost.Get_Files();

            if (dec_folder.files is List<sFile>)
                dec_file = dec_folder.files[0].path;
            else
            {
                string tempFile = Path.GetTempFileName();
                Byte[] compressFile = new Byte[(new FileInfo(file).Length) - 0x08];
                Array.Copy(File.ReadAllBytes(file), 0x08, compressFile, 0, compressFile.Length); ;
                File.WriteAllBytes(tempFile, compressFile);

                pluginHost.Decompress(tempFile);
                dec_file = pluginHost.Get_Files().files[0].path;
            }

            BinaryReader br = new BinaryReader(File.OpenRead(dec_file));

            // Bank info
            Ekona.Images.Bank[] banks = new Ekona.Images.Bank[br.ReadUInt32()];
            uint num_cells = br.ReadUInt32();
            uint unknown1 = br.ReadUInt32();

            for (int i = 0; i < banks.Length; i++)
            {
                uint unk = br.ReadUInt16();
                banks[i].oams = new OAM[br.ReadUInt16()];
            }

            // Read cell information
            for (int i = 0; i < banks.Length; i++)
            {
                for (int j = 0; j < banks[i].oams.Length; j++)
                {
                    banks[i].oams[j].obj1.xOffset = br.ReadInt16();
                    banks[i].oams[j].obj0.yOffset = br.ReadInt16();

                    uint size_b = br.ReadUInt32();
                    byte b1 = (byte)(size_b & 0x03);
                    byte b2 = (byte)((size_b & 0x0C) >> 2);
                    System.Drawing.Size size = Actions.Get_OAMSize(b1, b2);
                    banks[i].oams[j].width = (ushort)size.Width;
                    banks[i].oams[j].height = (ushort)size.Height;

                    banks[i].oams[j].obj2.tileOffset = br.ReadUInt32();
                    banks[i].oams[j].obj2.index_palette = 0;
                    banks[i].oams[j].num_cell = (ushort)j;
                }
            }
            Set_Banks(banks, 2, false);
            pluginHost.Set_Sprite(this);

            // Palette
            PaletteBase palette;
            int palette_length = (int)(br.BaseStream.Length - br.BaseStream.Position);
            Color[][] colors = new Color[1][];
            colors[0] = Actions.BGR555ToColor(br.ReadBytes(palette_length));

            br.Close();

            palette = new RawPalette(colors, false, (palette_length > 0x20) ? ColorFormat.colors256 : ColorFormat.colors16);
            pluginHost.Set_Palette(palette);
        }
Ejemplo n.º 9
0
Archivo: NCER.cs Proyecto: MetLob/tinke
        Bank[] Convert_Banks()
        {
            Bank[] banks = new Bank[ncer.cebk.banks.Length];
            for (int i = 0; i < banks.Length; i++)
            {
                banks[i].height = 0;
                banks[i].width = 0;
                banks[i].oams = ncer.cebk.banks[i].oams;
                if (ncer.labl.names.Length > i)
                    banks[i].name = ncer.labl.names[i];

                banks[i].data_offset = ncer.cebk.banks[i].partition_offset;
                banks[i].data_size = ncer.cebk.banks[i].partition_size;
            }
            return banks;
        }
Ejemplo n.º 10
0
        public override void Read(string file)
        {
            // It's compressed
            pluginHost.Decompress(file);
            string  dec_file;
            sFolder dec_folder = pluginHost.Get_Files();

            if (dec_folder.files is List <sFile> )
            {
                dec_file = dec_folder.files[0].path;
            }
            else
            {
                string tempFile     = Path.GetTempFileName();
                Byte[] compressFile = new Byte[(new FileInfo(file).Length) - 0x08];
                Array.Copy(File.ReadAllBytes(file), 0x08, compressFile, 0, compressFile.Length);;
                File.WriteAllBytes(tempFile, compressFile);

                pluginHost.Decompress(tempFile);
                dec_file = pluginHost.Get_Files().files[0].path;
            }

            BinaryReader br = new BinaryReader(File.OpenRead(dec_file));

            // Bank info
            Ekona.Images.Bank[] banks = new Ekona.Images.Bank[br.ReadUInt32()];
            uint num_cells            = br.ReadUInt32();
            uint unknown1             = br.ReadUInt32();

            for (int i = 0; i < banks.Length; i++)
            {
                uint unk = br.ReadUInt16();
                banks[i].oams = new OAM[br.ReadUInt16()];
            }

            // Read cell information
            for (int i = 0; i < banks.Length; i++)
            {
                for (int j = 0; j < banks[i].oams.Length; j++)
                {
                    banks[i].oams[j].obj1.xOffset = br.ReadInt16();
                    banks[i].oams[j].obj0.yOffset = br.ReadInt16();

                    uint size_b = br.ReadUInt32();
                    byte b1     = (byte)(size_b & 0x03);
                    byte b2     = (byte)((size_b & 0x0C) >> 2);
                    System.Drawing.Size size = Actions.Get_OAMSize(b1, b2);
                    banks[i].oams[j].width  = (ushort)size.Width;
                    banks[i].oams[j].height = (ushort)size.Height;

                    banks[i].oams[j].obj2.tileOffset    = br.ReadUInt32();
                    banks[i].oams[j].obj2.index_palette = 0;
                    banks[i].oams[j].num_cell           = (ushort)j;
                }
            }
            Set_Banks(banks, 2, false);
            pluginHost.Set_Sprite(this);

            // Palette
            PaletteBase palette;
            int         palette_length = (int)(br.BaseStream.Length - br.BaseStream.Position);

            Color[][] colors = new Color[1][];
            colors[0] = Actions.BGR555ToColor(br.ReadBytes(palette_length));

            br.Close();

            palette = new RawPalette(colors, false, (palette_length > 0x20) ? ColorFormat.colors256 : ColorFormat.colors16);
            pluginHost.Set_Palette(palette);
        }
Ejemplo n.º 11
0
Archivo: SIR0.cs Proyecto: MetLob/tinke
        public override void Read(string file)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(file));
            info = new SIR0_Info();

            PaletteBase palette;
            ImageBase image;
            Ekona.Images.Bank bank;

            // Read header
            char[] file_id = br.ReadChars(4);
            uint offset1 = br.ReadUInt32();
            uint offset2 = br.ReadUInt32();
            uint unknown = br.ReadUInt32();
            String name = "";
            do
            {
                byte c = br.ReadByte();
                if (c == 0xAA)
                    c = 0x00;
                name += (char)c;
            } while (name[name.Length - 1] != '\x0');

            // Read info section
            // Info 1
            br.BaseStream.Position = offset1;
            info.info1 = new SIR0_Info.Info1();
            info.info1.constant = br.ReadUInt32();
            info.info1.reserved = br.ReadBytes(0x3C);
            info.info1.info3_offset = br.ReadUInt32();
            info.info1.reserved2 = br.ReadBytes((int)(offset2 - offset1));
            // Info 2
            br.BaseStream.Position = offset2;
            info.info2 = new SIR0_Info.Info2();
            info.info2.unknown = br.ReadBytes(0x10);
            // Info 3
            br.BaseStream.Position = info.info1.info3_offset;
            info.info3 = new SIR0_Info.Info3();
            info.info3.tile_size = br.ReadUInt32();
            info.info3.unknown1 = br.ReadUInt32();
            info.info3.unknown2 = br.ReadUInt32();
            info.info3.unknown3 = br.ReadUInt32();
            info.info3.unknown4 = br.ReadUInt32();
            info.info3.palette_offset = br.ReadUInt32();
            info.info3.tile_offset = br.ReadUInt32();
            info.info3.cell_offset = br.ReadUInt32();
            info.info3.unknown5 = br.ReadUInt32();
            info.info3.reserved = br.ReadBytes(0x3C);

            // Read palette
            br.BaseStream.Position = info.info3.palette_offset;
            Color[][] colors = new Color[1][];
            colors[0] = Actions.BGR555ToColor(br.ReadBytes(0x200));
            palette = new RawPalette(colors, false, ColorFormat.colors256, "");

            // Read tiles
            br.BaseStream.Position = info.info3.tile_offset;
            byte[] tiles = new byte[info.info3.tile_size];
            tiles = br.ReadBytes((int)info.info3.tile_size);
            image = new RawImage(tiles, TileForm.Lineal, ColorFormat.colors256, 0x40,
                (int)(info.info3.tile_size / 0x40), false, "");

            // Read cell info
            uint bank_size;
            if (info.info3.unknown5 != 0x00)
                bank_size = info.info3.unknown5 - info.info3.cell_offset - 0x06;
            else
                bank_size = info.info1.info3_offset - info.info3.cell_offset - 0x06;

            br.BaseStream.Position = info.info3.cell_offset;
            bank = new Ekona.Images.Bank();
            bank.oams = new OAM[bank_size / 0x0A];
            for (int i = 0; i < bank.oams.Length; i++)
            {
                bank.oams[i].width = br.ReadUInt16();
                bank.oams[i].height = br.ReadUInt16();
                bank.oams[i].obj1.xOffset = br.ReadUInt16() - 0x80;
                bank.oams[i].obj0.yOffset = br.ReadUInt16() - 0x80;
                bank.oams[i].obj2.tileOffset = (uint)(br.ReadUInt16() / 0x20);
                bank.oams[i].num_cell = (ushort)i;
            }
            Set_Banks(new Ekona.Images.Bank[] { bank }, 0, false);
            br.Close();

            pluginHost.Set_Palette(palette);
            pluginHost.Set_Image(image);
            pluginHost.Set_Sprite(this);
        }