Exemplo n.º 1
0
        public bool saveallSprites()
        {
            byte[] sprites_buffer = new byte[0x1670];
            //empty room data = 0x250
            //start of data = 0x252
            try
            {
                int pos = 0x252;
                //set empty room
                sprites_buffer[0x250] = 0x00;
                sprites_buffer[0x251] = 0xFF;

                for (int i = 0; i < 296; i++)
                {
                    if (all_rooms[i].sprites.Count <= 0)
                    {
                        sprites_buffer[(i * 2)]     = (byte)((Addresses.pctosnes(Constants.sprites_data_empty_room) & 0xFF));
                        sprites_buffer[(i * 2) + 1] = (byte)((Addresses.pctosnes(Constants.sprites_data_empty_room) >> 8) & 0xFF);
                    }
                    else
                    {
                        //pointer :
                        sprites_buffer[(i * 2)]     = (byte)((Addresses.pctosnes(Constants.sprites_data + (pos - 0x252)) & 0xFF));
                        sprites_buffer[(i * 2) + 1] = (byte)((Addresses.pctosnes(Constants.sprites_data + (pos - 0x252)) >> 8) & 0xFF);
                        //ROM.DATA[sprite_address] == 1 ? true : false;
                        sprites_buffer[pos] = (byte)(all_rooms[i].sortSprites == true ? 0x01 : 0x00); //Unknown byte??
                        pos++;
                        foreach (Sprite spr in all_rooms[i].sprites)                                  //3bytes
                        {
                            byte b1 = (byte)((spr.layer << 7) + (spr.subtype << 5) + spr.y);
                            byte b2 = (byte)((spr.overlord << 5) + spr.x);
                            byte b3 = (byte)((spr.id));

                            sprites_buffer[pos] = b1;
                            pos++;
                            sprites_buffer[pos] = b2;
                            pos++;
                            sprites_buffer[pos] = b3;
                            pos++;

                            //if current sprite hold a key then save it before
                            if (spr.keyDrop == 1)
                            {
                                byte bb1 = (byte)(0xFE);
                                byte bb2 = (byte)(0x00);
                                byte bb3 = (byte)(0xE4);

                                sprites_buffer[pos] = bb1;
                                pos++;
                                sprites_buffer[pos] = bb2;
                                pos++;
                                sprites_buffer[pos] = bb3;
                                pos++;
                            }
                            if (spr.keyDrop == 2)
                            {
                                byte bb1 = (byte)(0xFD);
                                byte bb2 = (byte)(0x00);
                                byte bb3 = (byte)(0xE4);

                                sprites_buffer[pos] = bb1;
                                pos++;
                                sprites_buffer[pos] = bb2;
                                pos++;
                                sprites_buffer[pos] = bb3;
                                pos++;
                            }
                        }
                        sprites_buffer[pos] = 0xFF;//End of sprites
                        pos++;
                    }
                }
                int spritePointer = (04 << 16) + (ROM.DATA[Constants.rooms_sprite_pointer + 1] << 8) + (ROM.DATA[Constants.rooms_sprite_pointer]);
                sprites_buffer.CopyTo(ROM.DATA, spritePointer);
            }
            catch (Exception e)
            {
                return(true);
            }
            return(false); // False = no error
        }
Exemplo n.º 2
0
        public void DecompressAllMapTiles()
        {
            //int npos = 0;
            int sx = 0;
            int sy = 0;
            int c  = 0;

            for (int i = 0; i < 160; i++)
            {
                int p1 =
                    (ROM.DATA[(Constants.compressedAllMap32PointersHigh) + 2 + (int)(3 * i)] << 16) +
                    (ROM.DATA[(Constants.compressedAllMap32PointersHigh) + 1 + (int)(3 * i)] << 8) +
                    (ROM.DATA[(Constants.compressedAllMap32PointersHigh + (int)(3 * i))]);
                p1 = Addresses.snestopc(p1);

                int p2 =
                    (ROM.DATA[(Constants.compressedAllMap32PointersLow) + 2 + (int)(3 * i)] << 16) +
                    (ROM.DATA[(Constants.compressedAllMap32PointersLow) + 1 + (int)(3 * i)] << 8) +
                    (ROM.DATA[(Constants.compressedAllMap32PointersLow + (int)(3 * i))]);
                p2 = Addresses.snestopc(p2);

                int ttpos           = 0;
                int compressedSize1 = 0;
                int compressedSize2 = 0;


                byte[] bytes  = ZCompressLibrary.Decompress.ALTTPDecompressOverworld(ROM.DATA, p2, 1000, ref compressedSize1);
                byte[] bytes2 = ZCompressLibrary.Decompress.ALTTPDecompressOverworld(ROM.DATA, p1, 1000, ref compressedSize2);

                for (int y = 0; y < 16; y++)
                {
                    for (int x = 0; x < 16; x++)
                    {
                        ushort tidD = (ushort)((bytes2[ttpos] << 8) + bytes[ttpos]);

                        int tpos = tidD;
                        if (tpos < tiles32.Count)
                        {
                            //map16tiles[npos] = new Tile32(tiles32[tpos].tile0, tiles32[tpos].tile1, tiles32[tpos].tile2, tiles32[tpos].tile3);

                            if (i < 64)
                            {
                                allmapsTilesLW[(x * 2) + (sx * 32), (y * 2) + (sy * 32)]         = tiles32[tpos].tile0;
                                allmapsTilesLW[(x * 2) + 1 + (sx * 32), (y * 2) + (sy * 32)]     = tiles32[tpos].tile1;
                                allmapsTilesLW[(x * 2) + (sx * 32), (y * 2) + 1 + (sy * 32)]     = tiles32[tpos].tile2;
                                allmapsTilesLW[(x * 2) + 1 + (sx * 32), (y * 2) + 1 + (sy * 32)] = tiles32[tpos].tile3;
                            }
                            else if (i < 128 && i >= 64)
                            {
                                allmapsTilesDW[(x * 2) + (sx * 32), (y * 2) + (sy * 32)]         = tiles32[tpos].tile0;
                                allmapsTilesDW[(x * 2) + 1 + (sx * 32), (y * 2) + (sy * 32)]     = tiles32[tpos].tile1;
                                allmapsTilesDW[(x * 2) + (sx * 32), (y * 2) + 1 + (sy * 32)]     = tiles32[tpos].tile2;
                                allmapsTilesDW[(x * 2) + 1 + (sx * 32), (y * 2) + 1 + (sy * 32)] = tiles32[tpos].tile3;
                            }
                            else
                            {
                                allmapsTilesSP[(x * 2) + (sx * 32), (y * 2) + (sy * 32)]         = tiles32[tpos].tile0;
                                allmapsTilesSP[(x * 2) + 1 + (sx * 32), (y * 2) + (sy * 32)]     = tiles32[tpos].tile1;
                                allmapsTilesSP[(x * 2) + (sx * 32), (y * 2) + 1 + (sy * 32)]     = tiles32[tpos].tile2;
                                allmapsTilesSP[(x * 2) + 1 + (sx * 32), (y * 2) + 1 + (sy * 32)] = tiles32[tpos].tile3;
                            }
                        }
                        ttpos += 1;
                    }
                }
                sx++;
                if (sx >= 8)
                {
                    sy++;
                    sx = 0;
                }
                c++;
                if (c >= 64)
                {
                    sx = 0;
                    sy = 0;
                    c  = 0;
                }
            }
        }
Exemplo n.º 3
0
        public int getLongPointerSnestoPc(int pos)
        {
            int p = (ROM.DATA[pos + 2] << 16) + (ROM.DATA[pos + 1] << 8) + (ROM.DATA[pos]);

            return(Addresses.snestopc(p));
        }
Exemplo n.º 4
0
        public bool saveallPots()
        {
            int pos = ConstantsJP.items_data_start + 2; //skip 2 FF FF that are empty pointer

            for (int i = 0; i < 296; i++)
            {
                if (all_rooms[i].pot_items.Count == 0)
                {
                    ROM.DATA[ConstantsJP.room_items_pointers + (i * 2)]     = (byte)((Addresses.pctosnes(ConstantsJP.items_data_start) & 0xFF));
                    ROM.DATA[ConstantsJP.room_items_pointers + (i * 2) + 1] = (byte)((Addresses.pctosnes(ConstantsJP.items_data_start) >> 8) & 0xFF);
                    continue;
                }
                //pointer
                ROM.DATA[ConstantsJP.room_items_pointers + (i * 2)]     = (byte)((Addresses.pctosnes(pos) & 0xFF));
                ROM.DATA[ConstantsJP.room_items_pointers + (i * 2) + 1] = (byte)((Addresses.pctosnes(pos) >> 8) & 0xFF);
                for (int j = 0; j < all_rooms[i].pot_items.Count; j++)
                {
                    if (all_rooms[i].pot_items[j].layer == 0)
                    {
                        all_rooms[i].pot_items[j].bg2 = false;
                    }
                    else
                    {
                        all_rooms[i].pot_items[j].bg2 = true;
                    }

                    int xy = (((all_rooms[i].pot_items[j].y * 64) + all_rooms[i].pot_items[j].x) << 1);
                    ROM.DATA[pos] = (byte)(xy & 0xFF);
                    pos++;
                    ROM.DATA[pos] = (byte)(((xy >> 8) & 0xFF) + (all_rooms[i].pot_items[j].bg2 == true ? 0x20 : 0x00));
                    pos++;
                    ROM.DATA[pos] = all_rooms[i].pot_items[j].id;
                    pos++;
                }
                ROM.DATA[pos] = 0xFF;
                pos++;
                ROM.DATA[pos] = 0xFF;
                pos++;
                if (pos > ConstantsJP.items_data_end)
                {
                    return(true);
                }
            }
            return(false); // False = no error
        }
Exemplo n.º 5
0
        public void loadSprites(bool fromImport = false)
        {
            if (index < 144)
            {
                byte[] data = ROM.DATA;
                if (fromImport)
                {
                    data = ROM.IMPORTDATA;
                }
                bool newadress = false;
                if (data.Length > 0x100000)
                {
                    if (data[0x1083C0] == 0xFF)
                    {
                        newadress = true;
                    }
                }
                sprites[0] = new List <Sprite>();
                sprites[1] = new List <Sprite>();
                sprites[2] = new List <Sprite>();
                if (parent == index)
                {
                    int spritesAddress = Constants.overworldSpritesZelda;

                    int sprite_address_snes = (09 << 16) +
                                              (data[spritesAddress + (parent * 2) + 1] << 8) +
                                              data[spritesAddress + (parent * 2)];

                    if (newadress)
                    {
                        spritesAddress      = Constants.overworldSpritesZeldaEditor;
                        sprite_address_snes = (0x21 << 16) +
                                              (data[spritesAddress + (parent * 2) + 1] << 8) +
                                              data[spritesAddress + (parent * 2)];
                    }


                    int sprite_address = Addresses.snestopc(sprite_address_snes);
                    while (true)
                    {
                        byte b1 = data[sprite_address];
                        byte b2 = data[sprite_address + 1];
                        byte b3 = data[sprite_address + 2];

                        if (b1 == 0xFF)
                        {
                            break;
                        }

                        int fakeid = parent;
                        if (fakeid >= 64)
                        {
                            fakeid -= 64;
                        }
                        int my = (fakeid / 8);
                        int mx = fakeid - (my * 8);

                        int realX = ((b2 & 0x3F) * 16) + mx * 512;
                        int realY = ((b1 & 0x3F) * 16) + my * 512;



                        if (index >= 64)
                        {
                            sprites[0].Add(new Sprite((byte)parent, b3, (byte)(b2 & 0x3F), (byte)(b1 & 0x3F), ow.allmaps, realX, realY));
                        }
                        else
                        {
                            sprites[1].Add(new Sprite((byte)parent, b3, (byte)(b2 & 0x3F), (byte)(b1 & 0x3F), ow.allmaps, realX, realY));
                        }
                        sprite_address += 3;
                    }

                    spritesAddress      = Constants.overworldSpritesBegining;
                    sprite_address_snes = (09 << 16) +
                                          (data[spritesAddress + (parent * 2) + 1] << 8) +
                                          data[spritesAddress + (parent * 2)];


                    if (newadress)
                    {
                        spritesAddress      = Constants.overworldSpritesBeginingEditor;
                        sprite_address_snes = (0x21 << 16) +
                                              (data[spritesAddress + (parent * 2) + 1] << 8) +
                                              data[spritesAddress + (parent * 2)];
                    }

                    sprite_address = Addresses.snestopc(sprite_address_snes);
                    while (true)
                    {
                        byte b1 = data[sprite_address];
                        byte b2 = data[sprite_address + 1];
                        byte b3 = data[sprite_address + 2];

                        if (b1 == 0xFF)
                        {
                            break;
                        }

                        int fakeid = parent;
                        if (fakeid >= 64)
                        {
                            fakeid -= 64;
                        }
                        int my = (fakeid / 8);
                        int mx = fakeid - (my * 8);

                        int realX = ((b2 & 0x3F) * 16) + mx * 512;
                        int realY = ((b1 & 0x3F) * 16) + my * 512;


                        if (index >= 64)
                        {
                        }
                        else
                        {
                            sprites[0].Add(new Sprite((byte)parent, b3, (byte)(b2 & 0x3F), (byte)(b1 & 0x3F), ow.allmaps, realX, realY));
                        }
                        sprite_address += 3;
                    }

                    spritesAddress      = Constants.overworldSpritesAgahnim;
                    sprite_address_snes = (09 << 16) +
                                          (data[spritesAddress + (parent * 2) + 1] << 8) +
                                          data[spritesAddress + (parent * 2)];

                    if (newadress)
                    {
                        spritesAddress      = Constants.overworldSpritesAgahnimEditor;
                        sprite_address_snes = (0x21 << 16) +
                                              (data[spritesAddress + (parent * 2) + 1] << 8) +
                                              data[spritesAddress + (parent * 2)];
                    }

                    sprite_address = Addresses.snestopc(sprite_address_snes);
                    while (true)
                    {
                        byte b1 = data[sprite_address];
                        byte b2 = data[sprite_address + 1];
                        byte b3 = data[sprite_address + 2];

                        if (b1 == 0xFF)
                        {
                            break;
                        }

                        int fakeid = parent;
                        if (fakeid >= 64)
                        {
                            fakeid -= 64;
                        }
                        int my = (fakeid / 8);
                        int mx = fakeid - (my * 8);

                        int realX = ((b2 & 0x3F) * 16) + mx * 512;
                        int realY = ((b1 & 0x3F) * 16) + my * 512;


                        if (index >= 64)
                        {
                        }
                        else
                        {
                            sprites[2].Add(new Sprite((byte)parent, b3, (byte)(b2 & 0x3F), (byte)(b1 & 0x3F), ow.allmaps, realX, realY));
                        }
                        sprite_address += 3;
                    }
                }
            }
        }
Exemplo n.º 6
0
        public static Bitmap selectedtobmp(byte[] sheets, int p = 4, bool sprite = false)
        {
            byte[] blocks             = new byte[24];
            byte[] data               = new byte[blocks.Length * 0x1000];
            int    gfxanimatedPointer = (ROM.DATA[Constants.gfx_animated_pointer + 2] << 16) + (ROM.DATA[Constants.gfx_animated_pointer + 1] << 8) + (ROM.DATA[Constants.gfx_animated_pointer]);

            gfxanimatedPointer = Addresses.snestopc(gfxanimatedPointer);
            for (int i = 0; i < blocks.Length; i++)
            {
                if (i < sheets.Length)
                {
                    byte[] d  = GFX.bpp3snestoindexed(GFX.gfxdata, sheets[i]);
                    byte[] dd = new byte[0];
                    if (i == 6)
                    {
                        dd = GFX.bpp3snestoindexed(GFX.gfxdata, ROM.DATA[gfxanimatedPointer + 0]); //static animated gfx1
                    }
                    if (i == 7)
                    {
                        dd = GFX.bpp3snestoindexed(GFX.gfxdata, 92); //static animated gfx1
                    }
                    for (int j = 0; j < d.Length; j++)
                    {
                        data[(i * 0x1000) + j] = d[j];
                        if (i == 6)
                        {
                            if (j >= 0xC00)
                            {
                                data[(i * 0x1000) + j] = dd[j - 0xC00];
                            }
                        }
                        if (i == 7)
                        {
                            if (j < 0x400)
                            {
                                data[(i * 0x1000) + j] = dd[j];
                            }
                        }
                    }
                }
            }



            Bitmap b = new Bitmap(128, 256);

            begin_draw(b, 128, 256);
            unsafe
            {
                for (int x = 0; x < 128; x++)
                {
                    for (int y = 0; y < 32 * sheets.Length; y++)
                    {
                        int dest = (x + (y * 128)) * 4;
                        if (sprite == true)
                        {
                            GFX.currentData[dest]     = (GFX.spritesPalettes[data[(dest / 4)], p].B);
                            GFX.currentData[dest + 1] = (GFX.spritesPalettes[data[(dest / 4)], p].G);
                            GFX.currentData[dest + 2] = (GFX.spritesPalettes[data[(dest / 4)], p].R);
                            GFX.currentData[dest + 3] = 255;
                        }
                        else
                        {
                            GFX.currentData[dest]     = (GFX.loadedPalettes[data[(dest / 4)], p].B);
                            GFX.currentData[dest + 1] = (GFX.loadedPalettes[data[(dest / 4)], p].G);
                            GFX.currentData[dest + 2] = (GFX.loadedPalettes[data[(dest / 4)], p].R);
                            GFX.currentData[dest + 3] = 255;
                        }
                    }
                }
            }
            end_draw(b);
            return(b);
        }
Exemplo n.º 7
0
        public static byte[] DecompressTiles() //to gfx.bin
        {
            byte[] buffer = new byte[0x6F800]; // (185)
            byte[] bufferBlock;
            int    bufferPos = 0;

            for (int i = 0; i < 96; i++)
            {
                int    gfxPointer1 = Addresses.snestopc((ROM.DATA[Constants.gfx_1_pointer + 1] << 8) + (ROM.DATA[Constants.gfx_1_pointer]));
                int    gfxPointer2 = Addresses.snestopc((ROM.DATA[Constants.gfx_2_pointer + 1] << 8) + (ROM.DATA[Constants.gfx_2_pointer]));
                int    gfxPointer3 = Addresses.snestopc((ROM.DATA[Constants.gfx_3_pointer + 1] << 8) + (ROM.DATA[Constants.gfx_3_pointer]));
                byte[] b           = new byte[] { ROM.DATA[gfxPointer3 + i], ROM.DATA[gfxPointer2 + i], ROM.DATA[gfxPointer1 + i], 0 };
                int    addr        = BitConverter.ToInt32(b, 0);
                addresses[i] = Addresses.snestopc(addr);
                //Console.WriteLine(Addresses.snestopc(addr).ToString("X6"));
                byte[] tbufferBlock = ZCompressLibrary.Decompress.ALTTPDecompressGraphics(ROM.DATA, Addresses.snestopc(addr), 0x800, ref blockSize[i]);
                bufferBlock = tbufferBlock;
                if (tbufferBlock.Length != 0x600)
                {
                    bpp[i]      = 2;
                    bufferBlock = new byte[0x600];
                    for (int j = 0; j < 0x600; j++)
                    {
                        bufferBlock[j] = tbufferBlock[j];
                    }
                }
                else
                {
                    bpp[i] = 3;
                }
                //bufferBlock = Decompress(Addresses.snestopc(addr), ROM.DATA);
                for (int j = 0; j < bufferBlock.Length; j++)
                {
                    buffer[bufferPos] = bufferBlock[j];
                    bufferPos++;
                }
            }


            for (int i = 96; i < 223; i++)
            {
                bpp[i] = 3;
                if (i < 115 || i > 126) //not compressed
                {
                    int    gfxPointer1 = Addresses.snestopc((ROM.DATA[Constants.gfx_1_pointer + 1] << 8) + (ROM.DATA[Constants.gfx_1_pointer]));
                    int    gfxPointer2 = Addresses.snestopc((ROM.DATA[Constants.gfx_2_pointer + 1] << 8) + (ROM.DATA[Constants.gfx_2_pointer]));
                    int    gfxPointer3 = Addresses.snestopc((ROM.DATA[Constants.gfx_3_pointer + 1] << 8) + (ROM.DATA[Constants.gfx_3_pointer]));
                    byte[] b           = new byte[] { ROM.DATA[gfxPointer3 + i], ROM.DATA[gfxPointer2 + i], ROM.DATA[gfxPointer1 + i], 0 };
                    int    addr        = BitConverter.ToInt32(b, 0);
                    addresses[i] = Addresses.snestopc(addr);
                    byte[] tbufferBlock = ZCompressLibrary.Decompress.ALTTPDecompressGraphics(ROM.DATA, Addresses.snestopc(addr), 0x800, ref blockSize[i]);
                    bufferBlock = tbufferBlock;
                    if (tbufferBlock.Length != 0x600)
                    {
                        bpp[i]      = 2;
                        bufferBlock = new byte[0xC00];
                        Console.WriteLine(tbufferBlock.Length);
                        for (int j = 0; j < tbufferBlock.Length; j++)
                        {
                            bufferBlock[j] = tbufferBlock[j];
                        }
                    }

                    for (int j = 0; j < bufferBlock.Length; j++)
                    {
                        buffer[bufferPos] = bufferBlock[j];
                        bufferPos++;
                    }
                }
                else
                {
                    int    gfxPointer1 = Addresses.snestopc((ROM.DATA[Constants.gfx_1_pointer + 1] << 8) + (ROM.DATA[Constants.gfx_1_pointer]));
                    int    gfxPointer2 = Addresses.snestopc((ROM.DATA[Constants.gfx_2_pointer + 1] << 8) + (ROM.DATA[Constants.gfx_2_pointer]));
                    int    gfxPointer3 = Addresses.snestopc((ROM.DATA[Constants.gfx_3_pointer + 1] << 8) + (ROM.DATA[Constants.gfx_3_pointer]));
                    byte[] b           = new byte[] { ROM.DATA[gfxPointer3 + i], ROM.DATA[gfxPointer2 + i], ROM.DATA[gfxPointer1 + i], 0 };
                    int    addr        = BitConverter.ToInt32(b, 0);
                    addr   = Addresses.snestopc(addr);
                    bpp[i] = 3;
                    for (int j = 0; j < 0x600; j++)
                    {
                        buffer[bufferPos] = ROM.DATA[addr + j];
                        bufferPos++;
                    }
                }
            }
            FileStream fs = new FileStream("testgfx.gfx", FileMode.OpenOrCreate, FileAccess.Write);

            fs.Write(buffer.ToArray(), 0, buffer.Length);
            fs.Close();
            return(buffer);
        }