Esempio n. 1
0
 public void decompressAllGroups(MapLoader m, Program.GameTypes game)
 {
     if (game == Program.GameTypes.Ages)
     {
         for (int i = 0; i < 6; i++)
         {
             decompressGroup(i, m, game);
         }
     }
     else
     {
         /*for (int i = 0; i < 6; i++)
          * {
          *  DecompressGroupSeasons(i, m);
          * }*/
         DecompressGroupSeasons(0, m);
         DecompressGroupSeasons(1, m);
         DecompressGroupSeasons(4, m);
         DecompressGroupSeasons(5, m);
     }
 }
Esempio n. 2
0
        public void DecompressGroupSeasons(int group, MapLoader mapLoader)
        {
            if (gb.Buffer.Length == 0x100000)
            {
                throw new Exception("ROM has not been expanded.");
            }

            if (group == 0)
            {
                for (int season = 0; season < 4; season++)
                {
                    int address = 0x150000 + (season * 2) * 0x4000; //Bank 0x54
                    for (int i = 0; i < 256; i++)
                    {
                        mapLoader.loadMap(i, group, season, false, Program.GameTypes.Seasons);
                        MapLoader.Room r = mapLoader.room;

                        gb.BufferLocation = address;
                        gb.WriteBytes(r.decompressed);
                        int count = gb.BufferLocation - address;
                        address = gb.BufferLocation;

                        gb.BufferLocation = 0x42 * 0x4000 + season * 0x400 + i * 4;
                        gb.WriteByte(1);
                        gb.WriteByte((byte)((address - count) / 0x4000));
                        gb.WriteBytes(gb.Get2BytePointer(address - count));

                        //Write the new bank indexes

                        /*group = season; //7 + season;
                         * gb.BufferLocation = 0x5C * 0x4000 + group * 2;
                         * gb.WriteBytes(gb.Get2BytePointer(group * 0x100 + 0x20));
                         * gb.BufferLocation = 0x5C * 0x4000 + group * 0x100 + 0x20 + i;
                         * gb.WriteByte((byte)((address - count) / 0x4000));
                         * //Write the map-specific header
                         * gb.BufferLocation = 0x40 * 0x4000 + 0x200 + (0x200 * group) + (i * 2);
                         * byte[] b = gb.Get2BytePointer(address - count);
                         * gb.WriteBytes(new byte[] { b[0], (byte)(b[1] - 0x40) });
                         * group = 0;*/
                        //gb.WriteBytes(new byte[] { (byte)(count + (address % 0x4000)), (byte)((count + (address % 0x4000)) >> 8) });
                    }
                }
            }
            else if (group > 0 && group < 4)                   //Subrosia
            {
                int address = 0x104000 + (group * 2) * 0x4000; //Bank 0x41
                for (int i = 0; i < 256; i++)
                {
                    mapLoader.loadMap(i, group, 0, false, Program.GameTypes.Seasons);
                    MapLoader.Room r = mapLoader.room;

                    gb.BufferLocation = address;
                    gb.WriteBytes(r.decompressed);
                    int count = gb.BufferLocation - address;
                    address = gb.BufferLocation;

                    gb.BufferLocation = 0x42 * 0x4000 + 4 * 0x400 + i * 4;
                    gb.WriteByte(1);
                    gb.WriteByte((byte)((address - count) / 0x4000));
                    gb.WriteBytes(gb.Get2BytePointer(address - count));
                }
            }
            else
            {
                int address = 0x104000 + (group * 3) * 0x4000; //Bank 0x41
                for (int i = 0; i < 256; i++)
                {
                    mapLoader.loadMap(i, group, 0, false, Program.GameTypes.Seasons);
                    MapLoader.Room r = mapLoader.room;

                    gb.BufferLocation = address;
                    gb.WriteBytes(r.decompressed);
                    int count = gb.BufferLocation - address;
                    address = gb.BufferLocation;

                    gb.BufferLocation = 0x42 * 0x4000 + (group + 1) * 0x400 + i * 4;
                    gb.WriteByte(0);
                    gb.WriteByte((byte)((address - count) / 0x4000));
                    gb.WriteBytes(gb.Get2BytePointer(address - count));
                }
            }

            //Write the new region header
            int indexBase = 0x10C4C;

            if (group == 0)
            {
                for (int season = 0; season < 4; season++)
                {
                    byte a = (byte)(season * 8);
                    gb.BufferLocation = indexBase + a;
                    gb.WriteByte(1);                                                //The map type
                    gb.WriteByte(0x40);                                             //The header pointers will always be in bank 0x40
                    gb.WriteBytes(new byte[] { 0, (byte)(0x42 + (0x4 * season)) }); // The pointer. 0x300 bytes per group
                    //gb.WriteByte((byte)(0x41 + (season * 2)));
                    //gb.WriteBytes(new byte[] { 0, 0x40 }); //Temporary!!
                }
            }
            else
            {
                byte a = 0x20;
                if (group > 3)
                {
                    a += (byte)((group - 3) * 8);
                }
                gb.BufferLocation = indexBase + a;
                gb.WriteByte((byte)(group < 4 ? 1 : 0));                         //The map type
                gb.WriteByte(0x40);                                              //The header pointers will always be in bank 0x40
                gb.WriteBytes(new byte[] { 0, (byte)(0x42 + (0x4 * (a / 8))) }); // The pointer. 0x400 bytes per group
                //else
                //	gb.WriteBytes(new byte[] { 0, (byte)(0x32 + (0x3 * (a / 8))) }); //The relative minor pointer. Only 41 because the loading procedure address 0x1000

                /*if (group < 4)
                 *  gb.WriteByte((byte)(0x41 + ((a / 8) * 2)));
                 * else
                 *  gb.WriteByte((byte)(0x46 + (((a / 8) - 4) * 3)))*/
                //gb.WriteBytes(new byte[] { 0, 0x40 }); //Temporary!!
            }
        }
Esempio n. 3
0
        public void decompressGroup(int group, MapLoader mapLoader, Program.GameTypes game)
        {
            if (gb.Buffer.Length == 0x100000)
            {
                throw new Exception("ROM has not been expanded.");
            }

            if (group < 4)
            {
                int address = 0x104000 + (group * 2) * 0x4000; //Bank 0x41

                for (int i = 0; i < 256; i++)
                {
                    /*int rg = group;
                     * if (group == 1)
                     *  rg = 2;
                     * else if (group == 2)
                     *  rg = 1;*/
                    mapLoader.loadMap(i, group, 0, false, game);
                    MapLoader.Room r = mapLoader.room;

                    gb.BufferLocation = address;
                    gb.WriteBytes(r.decompressed);
                    int count = gb.BufferLocation - address;
                    address = gb.BufferLocation;

                    //Write the new bank indexes
                    gb.BufferLocation = 0x54 * 0x4000 + group * 2;
                    gb.WriteBytes(gb.Get2BytePointer(group * 0x100 + 0x20));
                    gb.BufferLocation = 0x54 * 0x4000 + group * 0x100 + 0x20 + i;
                    gb.WriteByte((byte)((address - count) / 0x4000));
                    //Write the map-specific header
                    gb.BufferLocation = 0x40 * 0x4000 + 0x200 + (0x200 * group) + (i * 2);
                    byte[] b = gb.Get2BytePointer(address - count);
                    gb.WriteBytes(new byte[] { b[0], (byte)(b[1] - 0x40) });
                    //gb.WriteBytes(new byte[] { (byte)(count + (address % 0x4000)), (byte)((count + (address % 0x4000)) >> 8) });
                }
            }
            else
            {
                int address = 0x104000 + (group * 3) * 0x4000; //Bank 0x41
                for (int i = 0; i < 256; i++)
                {
                    mapLoader.loadMap(i, group, 0, false, game);
                    MapLoader.Room r = mapLoader.room;

                    gb.BufferLocation = address;
                    gb.WriteBytes(r.decompressed);
                    int count = gb.BufferLocation - address;
                    address = gb.BufferLocation;

                    //Write the new bank indexes
                    gb.BufferLocation = 0x54 * 0x4000 + group * 2;
                    gb.WriteBytes(gb.Get2BytePointer(group * 0x100 + 0x20));
                    gb.BufferLocation = 0x54 * 0x4000 + group * 0x100 + 0x20 + i;
                    gb.WriteByte((byte)((address - count) / 0x4000));

                    gb.BufferLocation = 0x40 * 0x4000 + 0x200 + (0x200 * group) + (i * 2);
                    byte[] p = gb.Get2BytePointer(address - count);
                    gb.WriteBytes(new byte[] { p[0], (byte)(p[1] + 2) }); //TEMPORARY!
                }
            }

            //Write the new region header
            int  indexBase = 0x10000 + (game == Program.GameTypes.Ages ? 0x0F6C : 0x0C4C);
            byte a         = (byte)(group * 8);

            gb.BufferLocation = indexBase + a;
            gb.WriteByte((byte)(group < 4 ? 1 : 0)); //The map type
            gb.WriteByte(0x40);                      //The header pointers will always be in bank 0x40
            if (group < 4)
            {
                gb.WriteBytes(new byte[] { 0, (byte)(0x42 + (0x2 * group)) }); // The pointer. 0x200 bytes per group
            }
            else
            {
                gb.WriteBytes(new byte[] { 0, (byte)(0x32 + (0x2 * group)) }); //The relative minor pointer. Only 41 because the loading procedure address 0x1000
            }
            if (group < 4)
            {
                gb.WriteByte((byte)(0x41 + (group * 2)));
            }
            else
            {
                gb.WriteByte((byte)(0x46 + ((group - 4) * 3)));
            }
            gb.WriteBytes(new byte[] { 0, 0x40 }); //Temporary!!
        }