Beispiel #1
0
        public static byte[] DecompressTiles() //to gfx.bin
        {
            byte[] buffer = new byte[0x63000]; // (185)
            byte[] bufferBlock;
            int    bufferPos = 0;

            for (int i = 0; i < 96; i++)
            {
                byte[] b    = new byte[] { ROM.DATA[Constants.gfx_pointer_3 + i], ROM.DATA[Constants.gfx_pointer_2 + i], ROM.DATA[Constants.gfx_pointer_1 + i], 0 };
                int    addr = BitConverter.ToInt32(b, 0);
                bufferBlock = Decompress(Addresses.snestopc(addr), ROM.DATA);
                for (int j = 0; j < bufferBlock.Length; j++)
                {
                    buffer[bufferPos] = bufferBlock[j];
                    bufferPos++;
                }
            }

            for (int i = 115; i < 216; i++)
            {
                if (i < 115 || i > 126)
                {
                    byte[] b    = new byte[] { ROM.DATA[Constants.gfx_pointer_3 + i], ROM.DATA[Constants.gfx_pointer_2 + i], ROM.DATA[Constants.gfx_pointer_1 + i], 0 };
                    int    addr = BitConverter.ToInt32(b, 0);
                    bufferBlock = Decompress(Addresses.snestopc(addr), ROM.DATA);
                    if (bufferBlock.Length == 0x600)
                    {
                        for (int j = 0; j < bufferBlock.Length; j++)
                        {
                            buffer[bufferPos] = bufferBlock[j];
                            bufferPos++;
                        }
                    }
                }
                else
                {
                    byte[] b    = new byte[] { ROM.DATA[Constants.gfx_pointer_3 + i], ROM.DATA[Constants.gfx_pointer_2 + i], ROM.DATA[Constants.gfx_pointer_1 + i], 0 };
                    int    addr = BitConverter.ToInt32(b, 0);
                    addr = Addresses.snestopc(addr);
                    for (int j = 0; j < 0x600; j++)
                    {
                        buffer[bufferPos] = ROM.DATA[addr + j];
                        bufferPos++;
                    }
                }
            }
            if (Constants.Rando)
            {
                bufferBlock = Decompress(0x18A800, ROM.DATA);
                for (int j = 0; j < 0x600; j++)
                {
                    buffer[bufferPos] = bufferBlock[j];
                    bufferPos++;
                }
            }



            return(buffer);
        }
Beispiel #2
0
        public bool saveallChests()
        {
            int cpos = (ROM.DATA[Constants.chests_data_pointer1 + 2] << 16) + (ROM.DATA[Constants.chests_data_pointer1 + 1] << 8) + (ROM.DATA[Constants.chests_data_pointer1]);

            cpos = Addresses.snestopc(cpos);
            int chestCount = 0;

            for (int i = 0; i < 296; i++)
            {
                //number of possible chests
                foreach (Chest c in all_rooms[i].chest_list)
                {
                    ushort room_index = (ushort)i;
                    if (c.bigChest == true)
                    {
                        room_index += 0x8000;
                    }
                    ROM.DATA[cpos]     = (byte)(room_index & 0xFF);
                    ROM.DATA[cpos + 1] = (byte)((room_index >> 8) & 0xFF);
                    ROM.DATA[cpos + 2] = (byte)(c.item);
                    cpos += 3;
                    chestCount++;
                }
            }
            Console.WriteLine("Nbr of chests : " + chestCount);
            if (chestCount > 168)
            {
                return(true); // False = no error
            }
            return(false);    // False = no error
        }
Beispiel #3
0
        public bool saveRoomsHeaders()
        {
            //long??
            int headerPointer = (ROM.DATA[Constants.room_header_pointer + 2] << 16) + (ROM.DATA[Constants.room_header_pointer + 1] << 8) + (ROM.DATA[Constants.room_header_pointer]);

            headerPointer = Addresses.snestopc(headerPointer);
            //headerPointer = 04F1E2 topc -> 0271E2
            if (Constants.Rando)
            {
                //24
                ROM.DATA[Constants.room_header_pointers_bank] = 0x24;
                for (int i = 0; i < 296; i++)
                {
                    ROM.DATA[headerPointer + (i * 2)]     = (byte)((Addresses.pctosnes(newHeaderPos + (i * 14)) & 0xFF));
                    ROM.DATA[headerPointer + (i * 2) + 1] = (byte)((Addresses.pctosnes(newHeaderPos + (i * 14)) >> 8) & 0xFF);
                    saveHeader(newHeaderPos, i);
                    //savetext
                    //(short)((ROM.DATA[Constants.messages_id_dungeon + (index * 2) + 1] << 8) + ROM.DATA[Constants.messages_id_dungeon + (index * 2)])
                    ROM.DATA[Constants.messages_id_dungeon + (i * 2)]     = (byte)(all_rooms[i].messageid & 0xFF);
                    ROM.DATA[Constants.messages_id_dungeon + (i * 2) + 1] = (byte)((all_rooms[i].messageid >> 8) & 0xFF);
                }
            }
            else
            {
                ROM.DATA[Constants.room_header_pointers_bank] = 0x22;
                for (int i = 0; i < 296; i++)
                {
                    ROM.DATA[headerPointer + (i * 2)]     = (byte)((Addresses.pctosnes(0x110000 + (i * 14)) & 0xFF));
                    ROM.DATA[headerPointer + (i * 2) + 1] = (byte)((Addresses.pctosnes(0x110000 + (i * 14)) >> 8) & 0xFF);
                    saveHeader(0x110000, i);
                }
            }
            return(false); // False = no error
        }
Beispiel #4
0
        public void addItems()
        {
            int addr = (Constants.overworldItemsBank << 16) +
                       (ROM.DATA[Constants.overworldItemsPointers + (index * 2) + 1] << 8) +
                       (ROM.DATA[Constants.overworldItemsPointers + (index * 2)]);

            addr = Addresses.snestopc(addr);

            while (true)
            {
                byte b1 = ROM.DATA[addr];
                byte b2 = ROM.DATA[addr + 1];
                byte b3 = ROM.DATA[addr + 2];
                if (b1 == 0xFF && b2 == 0xFF)
                {
                    break;
                }

                int p = (((b2 & 0x1F) << 8) + b1) >> 1;

                int x = p % 64;
                int y = p >> 6;

                items.Add(new PotItem(b3, (byte)x, (byte)y, false));
                addr += 3;
            }
        }
        public void loadItems()
        {
            int ptr = (ROM.DATA[Constants.overworldItemsAddress + 2] << 16) +
                      (ROM.DATA[Constants.overworldItemsAddress + 1] << 8) +
                      (ROM.DATA[Constants.overworldItemsAddress]); //1BC2F9

            for (int i = 0; i < 128; i++)
            {
                int ptrpc = Addresses.snestopc(ptr);               //1BC2F9 -> 0DC2F9
                int addr  = ((ptr & 0xFF0000)) +                   //1B
                            (ROM.DATA[ptrpc + (i * 2) + 1] << 8) + //F9
                            (ROM.DATA[ptrpc + (i * 2)]);           //3C

                addr = Addresses.snestopc(addr);

                if (allmaps[i].largeMap == true)
                {
                    if (mapParent[i] != (byte)i)
                    {
                        continue;
                    }
                }
                while (true)
                {
                    byte b1 = ROM.DATA[addr];
                    byte b2 = ROM.DATA[addr + 1];
                    byte b3 = ROM.DATA[addr + 2];
                    if (b1 == 0xFF && b2 == 0xFF)
                    {
                        break;
                    }

                    int p = (((b2 & 0x1F) << 8) + b1) >> 1;

                    int x = p % 64;
                    int y = p >> 6;

                    int fakeid = i;
                    if (fakeid >= 64)
                    {
                        fakeid -= 64;
                    }
                    int sy = (fakeid / 8);
                    int sx = fakeid - (sy * 8);

                    allitems.Add(new RoomPotSaveEditor(b3, (ushort)i, (x * 16) + (sx * 512), (y * 16) + (sy * 512), false));
                    if (i == 64)
                    {
                        Console.WriteLine("X : " + x * 16 + ", Y:" + y * 16);
                    }
                    allitems[allitems.Count - 1].gameX = (byte)x;
                    allitems[allitems.Count - 1].gameY = (byte)y;
                    addr += 3;
                }
            }
        }
Beispiel #6
0
        public static void DecompressAllMapTiles()
        {
            int npos = 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 < GFX.tiles32.Count)
                        {
                            map16tiles[npos] = new Tile32(GFX.tiles32[tpos].tile0, GFX.tiles32[tpos].tile1, GFX.tiles32[tpos].tile2, GFX.tiles32[tpos].tile3);
                        }
                        else
                        {
                            map16tiles[npos] = new Tile32(0, 0, 0, 0);
                        }
                        if (i == 0)
                        {
                            //Console.Write(tpos + ",");
                        }
                        npos++;
                        ttpos += 1;
                    }
                }
            }
        }
Beispiel #7
0
        void saveObjectBytes(int roomId, int position, byte[] bytes, int doorOffset)
        {
            int objectPointer = (ROM.DATA[Constants.room_object_pointer + 2] << 16) + (ROM.DATA[Constants.room_object_pointer + 1] << 8) + (ROM.DATA[Constants.room_object_pointer]);

            objectPointer = Addresses.snestopc(objectPointer);
            saddr         = Addresses.pctosnes(position);
            int daddr = Addresses.pctosnes(position + doorOffset);

            // update the index
            ROM.DATA[objectPointer + (roomId * 3)]     = (byte)(saddr & 0xFF);
            ROM.DATA[objectPointer + (roomId * 3) + 1] = (byte)((saddr >> 8) & 0xFF);
            ROM.DATA[objectPointer + (roomId * 3) + 2] = (byte)((saddr >> 16) & 0xFF);

            ROM.DATA[Constants.doorPointers + (roomId * 3)]     = (byte)(daddr & 0xFF);
            ROM.DATA[Constants.doorPointers + (roomId * 3) + 1] = (byte)((daddr >> 8) & 0xFF);
            ROM.DATA[Constants.doorPointers + (roomId * 3) + 2] = (byte)((daddr >> 16) & 0xFF);

            Array.Copy(bytes, 0, ROM.DATA, position, bytes.Length);
        }
Beispiel #8
0
        public void addSprites(int address)
        {
            //09 bank ? Need to check if HM change that
            int sprite_address_snes = (09 << 16) +
                                      (ROM.DATA[address + (room.index * 2) + 1] << 8) +
                                      ROM.DATA[address + (room.index * 2)];
            int sprite_address = Addresses.snestopc(sprite_address_snes);

            while (true)
            {
                byte b1 = ROM.DATA[sprite_address];
                byte b2 = ROM.DATA[sprite_address + 1];
                byte b3 = ROM.DATA[sprite_address + 2];

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

                sprites.Add(new Sprite(null, b3, (byte)(b2 & 0x3F), (byte)(b1 & 0x3F), Sprites_Names.name[b3], 0, 0, 0));
                sprite_address += 3;
            }
        }
Beispiel #9
0
        public bool saveAllPits()
        {
            int pitCount   = (ROM.DATA[Constants.pit_count] / 2);
            int pitPointer = (ROM.DATA[Constants.pit_pointer + 2] << 16) + (ROM.DATA[Constants.pit_pointer + 1] << 8) + (ROM.DATA[Constants.pit_pointer]);

            pitPointer = Addresses.snestopc(pitPointer);
            int pitCountNew = 0;

            for (int i = 0; i < 296; i++)
            {
                if (all_rooms[i].damagepit)
                {
                    ROM.DATA[pitPointer + 1] = (byte)(all_rooms[i].index >> 8);
                    ROM.DATA[pitPointer]     = (byte)(all_rooms[i].index);
                    pitPointer += 2;
                    pitCountNew++;
                }
            }
            if (pitCountNew > pitCount)
            {
                return(true);
            }
            return(false);
        }
Beispiel #10
0
        public void drawOverlays()
        {
            //overlayPointers
            int addr = (Constants.overlayPointersBank << 16) +
                       (ROM.DATA[Constants.overlayPointers + (room.index * 2) + 1] << 8) +
                       ROM.DATA[Constants.overlayPointers + (room.index * 2)];

            addr = Addresses.snestopc(addr);

            int a   = 0;
            int x   = 0;
            int sta = 0;

            //16-bit mode :
            //A9 (LDA #$)
            //A2 (LDX #$)
            //8D (STA $xxxx)
            //9D (STA $xxxx ,x)
            //8F (STA $xxxxxx)
            //1A (INC A)
            //4C (JMP)
            //60 (END)

            for (int i = 0; i < 64; i++)
            {
                for (int j = 0; j < 64; j++)
                {
                    mapDataOverlay16[i, j] = 5000;
                }
            }


            byte b = 0;

            while (b != 0x60)
            {
                b = ROM.DATA[addr];
                if (b == 0xA9) //LDA #$xxxx (Increase addr+3)
                {
                    a = (ROM.DATA[addr + 2] << 8) +
                        ROM.DATA[addr + 1];
                    addr += 3;
                    continue;
                }
                else if (b == 0xA2) //LDX #$xxxx (Increase addr+3)
                {
                    x = (ROM.DATA[addr + 2] << 8) +
                        ROM.DATA[addr + 1];
                    addr += 3;
                    continue;
                }
                else if (b == 0x8D) //STA $xxxx (Increase addr+3)
                {
                    sta = (ROM.DATA[addr + 2] << 8) +
                          ROM.DATA[addr + 1];

                    //draw tile at sta position
                    Console.WriteLine("Draw Tile" + a + " at " + sta.ToString("X4"));
                    //64
                    sta = sta & 0x1FFF;
                    int yp = ((sta / 2) / 0x40);
                    int xp = (sta / 2) - (yp * 0x40);
                    mapDataOverlay16[xp, yp] = (ushort)a;

                    addr += 3;
                    continue;
                }
                else if (b == 0x9D) //STA $xxxx, x (Increase addr+3)
                {
                    sta = (ROM.DATA[addr + 2] << 8) +
                          ROM.DATA[addr + 1];
                    //draw tile at sta,X position
                    Console.WriteLine("Draw Tile" + a + " at " + (sta + x).ToString("X4"));

                    int stax = (sta & 0x1FFF) + x;
                    int yp   = ((stax / 2) / 0x40);
                    int xp   = (stax / 2) - (yp * 0x40);
                    mapDataOverlay16[xp, yp] = (ushort)a;

                    addr += 3;
                    continue;
                }
                else if (b == 0x8F) //STA $xxxxxx (Increase addr+4)
                {
                    sta = (ROM.DATA[addr + 2] << 8) +
                          ROM.DATA[addr + 1];
                    //draw tile at sta,X position
                    Console.WriteLine("Draw Tile" + a + " at " + (sta + x).ToString("X4"));

                    int stax = (sta & 0x1FFF) + x;
                    int yp   = ((stax / 2) / 0x40);
                    int xp   = (stax / 2) - (yp * 0x40);
                    mapDataOverlay16[xp, yp] = (ushort)a;

                    addr += 4;
                    continue;
                }
                else if (b == 0x1A) //INC A (Increase addr+1)
                {
                    a    += 1;
                    addr += 1;
                    continue;
                }
                else if (b == 0x4C) //JMP $xxxx (move addr to the new address)
                {
                    addr = (Constants.overlayPointersBank << 16) +
                           (ROM.DATA[addr + 2] << 8) +
                           ROM.DATA[addr + 1];
                    addr = Addresses.snestopc(addr);
                    continue;
                }
                else if (b == 0x60) //RTS
                {
                    break;          //just to be sure
                }
            }
        }
        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;
                }
            }
        }
Beispiel #12
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));
        }
Beispiel #13
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;
                    }
                }
            }
        }
Beispiel #14
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);
        }
Beispiel #15
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);
        }