Ejemplo n.º 1
0
        public SharedSecretBase(byte[] data, SecretBaseManager secretBaseManager)
        {
            if (data.Length != 160)
            {
                throw new Exception("Shared Secret Base must be 160 bytes in length");
            }
            this.secretBaseManager = secretBaseManager;
            this.raw = data;
            this.placedDecorations = new List <PlacedDecoration>();
            this.pokemonTeam       = new List <GBAPokemon>();

            for (int i = 0; i < 16; i++)
            {
                byte id = raw[0x12 + i];
                if (id != 0)
                {
                    byte x = ByteHelper.BitsToByte(raw, 0x22 + i, 4, 4);
                    byte y = ByteHelper.BitsToByte(raw, 0x22 + i, 0, 4);
                    placedDecorations.Add(new PlacedDecoration(id, x, y));
                }
            }

            for (int i = 0; i < 6; i++)
            {
                ushort species = LittleEndian.ToUInt16(raw, 0x7C + i * 2);

                if (species != 0 && PokemonDatabase.GetPokemonFromID(species) != null)
                {
                    uint     personality = LittleEndian.ToUInt32(raw, 0x34 + i * 4);
                    ushort[] moves       = new ushort[4];
                    for (int j = 0; j < 4; j++)
                    {
                        moves[j] = LittleEndian.ToUInt16(raw, 0x4C + j * 2 + i * 8);
                    }
                    ushort heldItem = LittleEndian.ToUInt16(raw, 0x88 + i * 2);
                    byte   level    = raw[0x94 + i];
                    byte   unknown  = raw[0x9A + i];

                    GBAPokemon pokemon = new GBAPokemon();
                    pokemon.SpeciesID   = species;
                    pokemon.Personality = personality;
                    pokemon.TrainerID   = TrainerID;
                    pokemon.SecretID    = SecretID;
                    pokemon.Nickname    = pokemon.PokemonData.Name.ToUpper();
                    for (int j = 0; j < 4; j++)
                    {
                        pokemon.SetMoveAt(j, new Move(moves[j]));
                    }
                    pokemon.HeldItemID = heldItem;
                    pokemon.Language   = Languages.English;
                    pokemon.Experience = PokemonDatabase.GetExperienceFromLevel(pokemon.PokemonData.ExperienceGroup, level);
                    pokemon.Level      = level;
                    pokemon.RecalculateStats();
                    pokemonTeam.Add(pokemon);
                }
            }
        }