示例#1
0
        public void LoadBackgroundTileMap(int compressedFileIndex)
        {
            background_tilemap = Decompressor.Decompress(compressedFileIndex).ToArray();

            //C0/0037

            //get number of tiles wide (seems to overshoot by one?)
            tilemap_width = BitConverter.ToUInt16(background_tilemap, 0x02); //stored at 0x0DE7 + 0x0A in original game (for outside first rubble room, at least.) And also store to 0x0A36

            //get number of tiles high (seems to overshoot by one?)
            tilemap_height = BitConverter.ToUInt16(background_tilemap, 0x00);    //stored at 0x0DE7 + 0x0C in original game (for outside first rubble room, at least.) And also store to 0x0A38

            //maybe the tilemaps aren't just straight data, obviously they've got those four bytes at the start for height and width (see immediately above), but could there still be other things mixed in with the data. It gets loaded in column-of-two by column-of-two - is there any data between those columns?
            //File.WriteAllBytes(Application.streamingAssetsPath + "\\decompressed", background_tilemap);
        }
示例#2
0
        public void LoadBackgroundPalette(int index)
        {
            uint currentOffset;

            background_palettes[0] = rom.BGPalette0;

            if (index != 0)
            {
                background_palettes    = new Palette[8];
                background_palettes[0] = rom.BGPalette0;

                byte[] paletteBytes = Decompressor.Decompress(index).ToArray();

                //this brings us to the address for a block of palettes to load into the background. Note that there is actually a value here that seems to be *how long* the block is (usually E0, for writing 7 of the eight palettes). But some of these are bigger than the 8 palettes for the BG. How can this be? Do they write to the sprite palette too?

                int lengthOfBlock = paletteBytes.Length;
                currentOffset = 0;

                Console.WriteLine("Loading palette block at address " + currentOffset);

                for (int i = 0x00; i < (lengthOfBlock / 0x20); i++) //load the palettes at the address into the background palette array
                {
                    if (lengthOfBlock <= 0xE0)                      //7 palettes, so just write to the ones after the global palette
                    {
                        background_palettes[i + 1] = imageTools.GetPaletteAtOffset(paletteBytes, (int)currentOffset, true);
                        currentOffset += 0x20;
                    }
                    else if (lengthOfBlock <= 0x100)    //8 palettes, so assume we're meant to write to the global palette too.
                    {
                        background_palettes[i] = imageTools.GetPaletteAtOffset(paletteBytes, (int)currentOffset, true);
                        currentOffset         += 0x20;
                    }
                    else
                    {
                        System.Windows.Forms.MessageBox.Show("Large palette! maybe it's supposed to write to the sprite palettes too?");
                        Console.WriteLine("Wtf? The palette block is bigger than the background palette count. Maybe it's meant to write to the sprite palettes, too?");
                    }
                }
            }
        }
示例#3
0
        public void LoadBackgroundTileGraphics(int compressedFileIndex)
        {
            Byte[] background_graphics = Decompressor.Decompress(compressedFileIndex).ToArray();

            ushort  tileAttribute = 0;
            ushort  tileID        = 0;
            Byte    PaletteID     = 0;
            Palette palette       = null;

            int tilemap_pos_X = 0;
            int tilemap_pos_Y = 0;

            background = new Bitmap(tilemap_width * 8, tilemap_height * 8);


            for (int i = 0x04; i < background_tilemap.Length; i += 4)
            {
                if (tilemap_pos_Y == 0 && tilemap_pos_X != 0)
                {
                    i += (tilemap_height * 2);
                }

                if (i >= background_tilemap.Length)
                {
                    break;
                }

                for (int j = 0; j < 4; j++)
                {
                    int tileAdditionalOffset = 0;   //to get the top left, top right, bottom left, bottom right minitiles

                    if (j == 0)                     //if top left tile
                    {
                        tileAdditionalOffset = 0;
                    }
                    else if (j == 1)                                 //if top right tile
                    {
                        tileAdditionalOffset = (tilemap_height * 2); //*2 because each value is 16bits
                    }
                    else if (j == 2)                                 //if bottom left tile
                    {
                        tileAdditionalOffset = 2;
                    }
                    else if (j == 3)                                     //if bottom right tile
                    {
                        tileAdditionalOffset = (tilemap_height * 2) + 2; //*2 because each value is 16bits
                    }

                    if ((i + tileAdditionalOffset) >= background_tilemap.Length)
                    {
                        break;
                    }

                    tileAttribute = BitConverter.ToUInt16(background_tilemap, i + tileAdditionalOffset);

                    tileID    = (ushort)(tileAttribute & 0x03FF);
                    PaletteID = (byte)(((tileAttribute & 0x3C00) >> 10) & 0xFF);

                    if (PaletteID < background_palettes.Length)
                    {
                        palette = background_palettes[PaletteID];          //load from background palettes
                    }
                    else if ((PaletteID - 8) < background_palettes.Length) //sometimes it's beyond 7, just move it back into the 0 to 7 range and it works
                    {
                        palette = background_palettes[PaletteID - 8];
                    }
                    else
                    {
                        Console.WriteLine("Could not locate palette in background palettes.");
                    }


                    bool flipY = false;
                    bool flipX = false;

                    if ((tileAttribute & 0x8000) == 0x8000)
                    {
                        flipY = true;
                    }                                                                                 //flipY (not yet implemented?)

                    if ((tileAttribute & 0x4000) == 0x4000)
                    {
                        flipX = true;
                    }                                                                                //flipX (not yet implemented?)

                    Bitmap tile = imageTools.GetTileRaw(background_graphics, tileID, palette);

                    imageTools.WriteImageIntoBiggerImage(background, tile, tilemap_pos_X * 8, tilemap_pos_Y * 8, flipX, flipY);

                    if (j == 0) //if top left tile just completed
                    {
                        tilemap_pos_X++;
                    }
                    else if (j == 1)                        //if top right tile just completed
                    {
                        tilemap_pos_X--;
                        tilemap_pos_Y++;

                        //in case we need to go to a new column early
                        if (tilemap_pos_Y >= (tilemap_height))
                        {
                            tilemap_pos_X += 2;
                            tilemap_pos_Y  = 0;
                        }

                        if (tilemap_pos_Y == 0 && tilemap_pos_X != 0)
                        {
                            i += (tilemap_height * 2);
                        }

                        if (i >= background_tilemap.Length)
                        {
                            break;
                        }
                    }
                    else if (j == 2)                        //if bottom left tile just completed
                    {
                        tilemap_pos_X++;
                    }
                    else if (j == 3)                        //if bottom right tile just completed
                    {
                        tilemap_pos_X--;
                        tilemap_pos_Y++;
                    }

                    if ((j == 0 || j == 2) && tilemap_pos_X >= tilemap_width) //if it's an odd number of tiles wide, then the last column can't be in the grid pattern
                    {
                        tilemap_pos_X--;
                        tilemap_pos_Y++;
                        j++;
                    }
                }

                if (tilemap_pos_Y >= (tilemap_height))
                {
                    tilemap_pos_X += 2;
                    tilemap_pos_Y  = 0;
                }
            }
        }