Exemple #1
0
        protected override void setDex(PKM pkm)
        {
            if (pkm.Species == 0)
            {
                return;
            }
            if (pkm.Species > MaxSpeciesID)
            {
                return;
            }
            if (Version == GameVersion.Unknown)
            {
                return;
            }
            if (PokeDex < 0)
            {
                return;
            }

            const int brSize = 0x54;
            int       bit    = pkm.Species - 1;
            int       lang   = pkm.Language - 1; if (lang > 5)
            {
                lang--;                    // 0-6 language vals
            }
            int gender   = pkm.Gender % 2; // genderless -> male
            int shiny    = pkm.IsShiny ? 1 : 0;
            int shiftoff = shiny * brSize * 2 + gender * brSize + brSize;

            // Set the Species Owned Flag
            Data[PokeDex + 0x8 + bit / 8] |= (byte)(1 << (bit % 8));

            // Set the [Species/Gender/Shiny] Seen Flag
            Data[PokeDex + 0x8 + shiftoff + bit / 8] |= (byte)(1 << (bit % 8));

            // Set the Display flag if none are set
            bool Displayed = false;

            Displayed |= (Data[PokeDex + 0x8 + brSize * 5 + bit / 8] & (byte)(1 << (bit % 8))) != 0;
            Displayed |= (Data[PokeDex + 0x8 + brSize * 6 + bit / 8] & (byte)(1 << (bit % 8))) != 0;
            Displayed |= (Data[PokeDex + 0x8 + brSize * 7 + bit / 8] & (byte)(1 << (bit % 8))) != 0;
            Displayed |= (Data[PokeDex + 0x8 + brSize * 8 + bit / 8] & (byte)(1 << (bit % 8))) != 0;
            if (!Displayed) // offset is already biased by brSize, reuse shiftoff but for the display flags.
            {
                Data[PokeDex + 0x8 + shiftoff + brSize * 4 + bit / 8] |= (byte)(1 << (bit % 8));
            }

            // Set the Language
            if (lang < 0)
            {
                lang = 1;
            }
            Data[PokeDexLanguageFlags + (bit * 7 + lang) / 8] |= (byte)(1 << ((bit * 7 + lang) % 8));

            // Formes
            int fc = Personal[pkm.Species].FormeCount;
            int f  = B2W2 ? SaveUtil.getDexFormIndexB2W2(pkm.Species, fc) : SaveUtil.getDexFormIndexBW(pkm.Species, fc);

            if (f < 0)
            {
                return;
            }

            int FormLen = B2W2 ? 0xB : 0x9;
            int FormDex = PokeDex + 0x8 + brSize * 9;

            bit = f + pkm.AltForm;

            // Set Form Seen Flag
            Data[FormDex + FormLen * shiny + bit / 8] |= (byte)(1 << (bit % 8));

            // Set Displayed Flag if necessary, check all flags
            for (int i = 0; i < fc; i++)
            {
                bit = f + i;
                if ((Data[FormDex + FormLen * 2 + bit / 8] & (byte)(1 << (bit % 8))) != 0) // Nonshiny
                {
                    return;                                                                // already set
                }
                if ((Data[FormDex + FormLen * 3 + bit / 8] & (byte)(1 << (bit % 8))) != 0) // Shiny
                {
                    return;                                                                // already set
                }
            }
            bit = f + pkm.AltForm;
            Data[FormDex + FormLen * (2 + shiny) + bit / 8] |= (byte)(1 << (bit % 8));
        }