Ejemplo n.º 1
0
        // assemblers
        private void Disassemble()
        {
            animationOffset = Bits.GetInt24(rom, 0x252000 + (index * 3)) - 0xC00000;
            int animationLength = Bits.GetShort(rom, animationOffset);

            buffer = Bits.GetBytes(rom, animationOffset, animationLength);
            //
            int    offset = 2;
            ushort sequencePacketPointer = Bits.GetShort(buffer, offset); offset += 2;
            ushort moldPacketPointer     = Bits.GetShort(buffer, offset); offset += 2;
            byte   sequenceCount         = buffer[offset++];
            byte   moldCount             = buffer[offset++];

            vramAllocation = (ushort)(buffer[offset] << 8); offset += 2;
            unknown        = Bits.GetShort(buffer, offset);
            //
            offset = sequencePacketPointer;
            for (int i = 0; i < sequenceCount; i++)
            {
                Sequence tSequence = new Sequence();
                tSequence.Disassemble(buffer, offset);
                sequences.Add(tSequence);
                offset += 2;
            }
            offset = moldPacketPointer;
            for (int i = 0; i < moldCount; i++)
            {
                Mold tMold = new Mold();
                tMold.Disassemble(buffer, offset, uniqueTiles, index, animationOffset);
                molds.Add(tMold);
                offset += 2;
            }
        }
Ejemplo n.º 2
0
        // public functions
        public void Refresh()
        {
            sequences   = new List <Sequence>();
            molds       = new List <Mold>();
            uniqueTiles = new List <Mold.Tile>();
            //
            int    offset = 2;
            ushort sequencePacketPointer = Bits.GetShort(buffer, offset); offset += 2;
            ushort moldPacketPointer     = Bits.GetShort(buffer, offset); offset += 2;
            byte   sequenceCount         = buffer[offset++];
            byte   moldCount             = buffer[offset++];

            vramAllocation = (ushort)(buffer[offset] << 8); offset += 2;
            unknown        = Bits.GetShort(buffer, offset);
            //
            offset = sequencePacketPointer;
            for (int i = 0; i < sequenceCount; i++)
            {
                Sequence tSequence = new Sequence();
                tSequence.Disassemble(buffer, offset);
                sequences.Add(tSequence);
                offset += 2;
            }
            offset = moldPacketPointer;
            for (int i = 0; i < moldCount; i++)
            {
                Mold tMold = new Mold();
                tMold.Disassemble(buffer, offset, uniqueTiles, index, animationOffset);
                molds.Add(tMold);
                offset += 2;
            }
        }
Ejemplo n.º 3
0
        // spawning
        public Mold New(bool gridplane)
        {
            Mold empty = new Mold();

            empty.Tiles.Add(new Mold.Tile().New(gridplane));
            empty.Gridplane = gridplane;
            return(empty);
        }
Ejemplo n.º 4
0
        public Mold Copy()
        {
            Mold copy = new Mold();

            copy.Tiles = new List <Tile>();
            foreach (Tile tile in tiles)
            {
                copy.Tiles.Add(tile.Copy());
            }
            copy.Gridplane = gridplane;
            return(copy);
        }
Ejemplo n.º 5
0
        public int[] GetTilesetPixels()
        {
            int offset        = image * 4 + 0x251800;
            int bank          = (int)(((rom[offset] & 0x0F) << 16) + 0x280000);
            int graphicOffset = (int)((Bits.GetShort(rom, offset) & 0xFFF0) + bank); offset += 2;

            //
            byte[]    graphics  = Bits.GetBytes(rom, graphicOffset, 0x4000);
            int[]     palette   = Palette;
            Animation animation = Model.Animations[animationPacket];
            Mold      mold      = animation.Molds[0];

            foreach (Mold.Tile tile in mold.Tiles)
            {
                tile.DrawSubtiles(graphics, palette, mold.Gridplane);
            }
            //
            return(animation.TilesetPixels());
        }
Ejemplo n.º 6
0
        // accessor functions
        /// <summary>
        /// Creates a pixel array of the sprite.
        /// </summary>
        /// <param name="byMold">Create the pixels by mold index.</param>
        /// <param name="byFCoord">Create the pixels by facing index.</param>
        /// <param name="moldIndex">The index of the mold (ignored if byMold == false).</param>
        /// <param name="fCoord">The index of the facing (ignored if byFacing == false)</param>
        /// <param name="palette">If want to use a particular palette.</param>
        /// <param name="mirror">Mirror the sprite pixels.</param>
        /// <param name="crop">Crop the sprite pixels to their edges.</param>
        /// <returns></returns>
        public int[] GetPixels(bool byMold, bool byFCoord, int moldIndex, int fCoord, int[] palette, bool mirror, bool crop, ref Size size)
        {
            // set palette to use
            if (palette == null)
            {
                palette = Palette;
            }
            // get offsets
            int animationNum    = Bits.GetShort(rom, this.index * 4 + 0x250002);
            int animationOffset = Bits.GetInt24(rom, 0x252000 + (animationNum * 3)) - 0xC00000;
            int animationLength = Bits.GetShort(rom, animationOffset);

            // get mold data
            byte[] sm     = Bits.GetBytes(rom, animationOffset, animationLength);
            int    offset = Bits.GetShort(sm, 2);

            if (byFCoord)
            {
                switch (fCoord)
                {
                case 0: mirror = !mirror; if (sm[6] < 13)
                    {
                        break;
                    }
                    offset += 24; break;

                case 1: mirror = !mirror; break;

                case 2: if (sm[6] < 11)
                    {
                        break;
                    }
                    offset += 20; break;

                case 4: if (sm[6] < 13)
                    {
                        break;
                    }
                    offset += 24; break;

                case 5: if (sm[6] < 2)
                    {
                        break;
                    }
                    offset += 2; break;

                case 6: if (sm[6] < 12)
                    {
                        break;
                    }
                    offset += 22; break;

                case 7: mirror = !mirror; if (sm[6] < 2)
                    {
                        break;
                    }
                    offset += 2; break;

                default: break;
                }
            }
            offset = Bits.GetShort(sm, offset);
            if (!byMold)
            {
                moldIndex = offset != 0xFFFF && sm[offset + 1] != 0 && sm[offset + 1] < sm[7] ? (int)sm[offset + 1] : 0;
            }
            offset  = Bits.GetShort(sm, 4);
            offset += moldIndex * 2;
            // create mold from data
            Mold mold = new Mold();

            mold.Disassemble(sm, offset, new List <Mold.Tile>(), animationNum, animationOffset);
            // generate subtiles in mold, then grab pixel array
            foreach (Mold.Tile t in mold.Tiles)
            {
                t.DrawSubtiles(Graphics, palette, mold.Gridplane);
            }
            int[] pixels = mold.MoldPixels();
            // crop image
            int lowY = 0, highY = 0, lowX = 0, highX = 0;

            if (crop)
            {
                bool stop = false;
                for (int y = 0; y < 256 && !stop; y++)
                {
                    for (int x = 0; x < 256; x++)
                    {
                        if (pixels[y * 256 + x] != 0)
                        {
                            lowY = y; lowX = x; stop = true; break;
                        }
                    }
                }
                stop = false;
                for (int y = 255; y >= 0 && !stop; y--)
                {
                    for (int x = 255; x >= 0; x--)
                    {
                        if (pixels[y * 256 + x] != 0)
                        {
                            highY = y; highX = x; stop = true; break;
                        }
                    }
                }
                stop = false;
                for (int y = 0; y < 256; y++)
                {
                    for (int x = 0; x < 256; x++)
                    {
                        if (pixels[y * 256 + x] != 0 && x < lowX)
                        {
                            lowX = x; break;
                        }
                    }
                }
                stop = false;
                for (int y = 255; y >= 0; y--)
                {
                    for (int x = 255; x >= 0; x--)
                    {
                        if (pixels[y * 256 + x] != 0 && x > highX)
                        {
                            highX = x; break;
                        }
                    }
                }
                stop = false;
                highY++; highX++;
            }
            else
            {
                highY = 256;
                highX = 256;
            }
            int imageHeight = highY - lowY;
            int imageWidth  = highX - lowX;

            if (crop)
            {
                int[] tempPixels = new int[imageWidth * imageHeight];
                for (int y = 0; y < imageHeight; y++)
                {
                    for (int x = 0; x < imageWidth; x++)
                    {
                        tempPixels[y * imageWidth + x] = pixels[(y + lowY) * 256 + x + lowX];
                    }
                }
                pixels = tempPixels;
            }
            int temp;

            if (mirror)
            {
                for (int y = 0; y < imageHeight; y++)
                {
                    for (int a = 0, c = imageWidth - 1; a < imageWidth / 2; a++, c--)
                    {
                        temp = pixels[(y * imageWidth) + a];
                        pixels[(y * imageWidth) + a] = pixels[(y * imageWidth) + c];
                        pixels[(y * imageWidth) + c] = temp;
                    }
                }
            }
            size = new Size(imageWidth, imageHeight);
            return(pixels);
        }