예제 #1
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);
        }
예제 #2
0
파일: SIR0.cs 프로젝트: 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);
        }