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

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

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

            // Owned quality flag
            if (origin < 0x18 && bit < 649 && !ORAS) // Species: 1-649 for X/Y, and not for ORAS; Set the Foreign Owned Flag
            {
                Data[PokeDex + 0x64C + bit / 8] |= (byte)(1 << (bit % 8));
            }
            else if (origin >= 0x18 || ORAS) // Set Native Owned Flag (should always happen)
            {
                Data[PokeDex + bit / 8 + 0x8] |= (byte)(1 << (bit % 8));
            }

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

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

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

            // Set DexNav count (only if not encountered previously)
            if (ORAS && getEncounterCount(pkm.Species - 1) == 0)
            {
                setEncounterCount(pkm.Species - 1, 1);
            }

            // Set Form flags
            int fc = Personal[pkm.Species].FormeCount;
            int f  = ORAS ? SaveUtil.getDexFormIndexORAS(pkm.Species, fc) : SaveUtil.getDexFormIndexXY(pkm.Species, fc);

            if (f < 0)
            {
                return;
            }

            int FormLen = ORAS ? 0x26 : 0x18;
            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));
        }
Exemplo n.º 2
0
        private void getEntry()
        {
            // Load Bools for the data
            int pk = species;

            L_Spinda.Visible = TB_Spinda.Visible = pk == 327;

            // Load Partitions
            for (int i = 0; i < 9; i++)
            {
                CP[i].Checked = specbools[i, pk - 1];
            }
            for (int i = 0; i < 7; i++)
            {
                CL[i].Checked = langbools[i, pk - 1];
            }

            if (pk < 650)
            {
                CHK_F1.Enabled = true; CHK_F1.Checked = foreignbools[pk - 1];
            }
            else
            {
                CHK_F1.Enabled = CHK_F1.Checked = false;
            }

            int gt = SAV.Personal[pk].Gender;

            CHK_P2.Enabled = CHK_P4.Enabled = CHK_P6.Enabled = CHK_P8.Enabled = gt != 254;                 // Not Female-Only
            CHK_P3.Enabled = CHK_P5.Enabled = CHK_P7.Enabled = CHK_P9.Enabled = !(gt == 0 || (gt == 255)); // Not Male-Only and Not Genderless

            CLB_FormsSeen.Items.Clear();
            CLB_FormDisplayed.Items.Clear();

            int fc = SAV.Personal[species].FormeCount;
            int f  = SaveUtil.getDexFormIndexXY(species, fc);

            if (f < 0)
            {
                return;
            }
            string[] forms = PKX.getFormList(species, Main.types, Main.forms, Main.gendersymbols);
            if (forms.Length < 1)
            {
                return;
            }

            // 0x26 packs of bools
            for (int i = 0; i < forms.Length; i++) // Seen
            {
                CLB_FormsSeen.Items.Add(forms[i], formbools[f + i + 0 * FormLen * 8]);
            }
            for (int i = 0; i < forms.Length; i++) // Seen Shiny
            {
                CLB_FormsSeen.Items.Add("* " + forms[i], formbools[f + i + 1 * FormLen * 8]);
            }

            for (int i = 0; i < forms.Length; i++) // Displayed
            {
                CLB_FormDisplayed.Items.Add(forms[i], formbools[f + i + 2 * FormLen * 8]);
            }
            for (int i = 0; i < forms.Length; i++) // Displayed Shiny
            {
                CLB_FormDisplayed.Items.Add("* " + forms[i], formbools[f + i + 3 * FormLen * 8]);
            }
        }
Exemplo n.º 3
0
        protected override void setDex(PKM pkm)
        {
            if (PokeDex < 0 || Version == GameVersion.Unknown) // sanity
            {
                return;
            }
            if (pkm.Species == 0 || pkm.Species > MaxSpeciesID) // out of range
            {
                return;
            }
            if (pkm.IsEgg) // do not add
            {
                return;
            }

            int bit    = pkm.Species - 1;
            int bd     = bit >> 3;       // div8
            int bm     = bit & 7;        // mod8
            int gender = pkm.Gender % 2; // genderless -> male
            int shiny  = pkm.IsShiny ? 1 : 0;

            if (pkm.Species == 351) // castform
            {
                shiny = 0;
            }
            int shift = gender | (shiny << 1);

            if (pkm.Species == 327)                                   // Spinda
            {
                if ((Data[PokeDex + 0x84] & (1 << (shift + 4))) != 0) // Already 2
                {
                    BitConverter.GetBytes(pkm.EncryptionConstant).CopyTo(Data, PokeDex + 0x8E8 + shift * 4);
                    // Data[PokeDex + 0x84] |= (byte)(1 << (shift + 4)); // 2 -- pointless
                    Data[PokeDex + 0x84] |= (byte)(1 << shift);      // 1
                }
                else if ((Data[PokeDex + 0x84] & (1 << shift)) == 0) // Not yet 1
                {
                    Data[PokeDex + 0x84] |= (byte)(1 << shift);      // 1
                }
            }
            int ofs = PokeDex // Raw Offset
                      + 0x08  // Magic + Flags
                      + 0x80; // Misc Data (1024 bits)

            // Set the Owned Flag
            Data[ofs + bd] |= (byte)(1 << bm);

            // Starting with Gen7, form bits are stored in the same region as the species flags.

            int  formstart = pkm.AltForm;
            int  formend = pkm.AltForm;
            int  fs, fe;
            bool reset = sanitizeFormsToIterate(pkm.Species, out fs, out fe, formstart);

            if (reset)
            {
                formstart = fs;
                formend   = fe;
            }

            for (int form = formstart; form <= formend; form++)
            {
                int bitIndex = bit;
                if (form > 0) // Override the bit to overwrite
                {
                    int fc = Personal[pkm.Species].FormeCount;
                    if (fc > 1) // actually has forms
                    {
                        int f = SaveUtil.getDexFormIndexSM(pkm.Species, fc, MaxSpeciesID - 1);
                        if (f >= 0) // bit index valid
                        {
                            bitIndex = f + form;
                        }
                    }
                }
                setDexFlags(bitIndex, gender, shiny, pkm.Species - 1);
            }

            // Set the Language
            int       lang      = pkm.Language;
            const int langCount = 9;

            if (lang <= 10 && lang != 6 && lang != 0) // valid language
            {
                if (lang >= 7)
                {
                    lang--;
                }
                lang--; // 0-8 languages
                if (lang < 0)
                {
                    lang = 1;
                }
                int lbit = bit * langCount + lang;
                if (lbit >> 3 < 920) // Sanity check for max length of region
                {
                    Data[PokeDexLanguageFlags + (lbit >> 3)] |= (byte)(1 << (lbit & 7));
                }
            }
        }
Exemplo n.º 4
0
        private void diffSaves()
        {
            if (!File.Exists(TB_OldSAV.Text))
            {
                Util.Alert("Save 1 path invalid."); return;
            }
            if (!File.Exists(TB_NewSAV.Text))
            {
                Util.Alert("Save 2 path invalid."); return;
            }
            if (new FileInfo(TB_OldSAV.Text).Length > 0x100000)
            {
                Util.Alert("Save 1 file invalid."); return;
            }
            if (new FileInfo(TB_NewSAV.Text).Length > 0x100000)
            {
                Util.Alert("Save 2 file invalid."); return;
            }

            SaveFile s1 = SaveUtil.getVariantSAV(File.ReadAllBytes(TB_OldSAV.Text));
            SaveFile s2 = SaveUtil.getVariantSAV(File.ReadAllBytes(TB_NewSAV.Text));

            if (s1.GetType() != s2.GetType())
            {
                Util.Alert("Save types are different.", $"S1: {s1.GetType()}", $"S2: {s2.GetType()}"); return;
            }
            if (s1.Version != s2.Version)
            {
                Util.Alert("Save versions are different.", $"S1: {s1.Version}", $"S2: {s2.Version}"); return;
            }

            string tbIsSet = "";
            string tbUnSet = "";

            try
            {
                bool[] oldBits = s1.EventFlags;
                bool[] newBits = s2.EventFlags;
                if (oldBits.Length != newBits.Length)
                {
                    Util.Alert("Event flag lengths for games are different.", $"S1: {(GameVersion)s1.Game}", $"S2: {(GameVersion)s2.Game}"); return;
                }

                for (int i = 0; i < oldBits.Length; i++)
                {
                    if (oldBits[i] == newBits[i])
                    {
                        continue;
                    }
                    if (newBits[i])
                    {
                        tbIsSet += i.ToString("0000") + ",";
                    }
                    else
                    {
                        tbUnSet += i.ToString("0000") + ",";
                    }
                }
            }
            catch (Exception e)
            {
                Util.Error(e.ToString());
                Console.Write(e);
            }
            TB_IsSet.Text = tbIsSet;
            TB_UnSet.Text = tbUnSet;

            string r = "";

            try
            {
                ushort[] oldConst = s1.EventConsts;
                ushort[] newConst = s2.EventConsts;
                if (oldConst.Length != newConst.Length)
                {
                    Util.Alert("Event flag lengths for games are different.", $"S1: {(GameVersion)s1.Game}", $"S2: {(GameVersion)s2.Game}"); return;
                }

                for (int i = 0; i < newConst.Length; i++)
                {
                    if (oldConst[i] != newConst[i])
                    {
                        r += $"{i}: {oldConst[i]}->{newConst[i]}{Environment.NewLine}";
                    }
                }
            }
            catch (Exception e)
            {
                Util.Error(e.ToString());
                Console.Write(e);
            }

            if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Copy Event Constant diff to clipboard?"))
            {
                return;
            }
            Clipboard.SetText(r);
        }
Exemplo n.º 5
0
        public SAV5(byte[] data = null, GameVersion versionOverride = GameVersion.Any)
        {
            Data       = data == null ? new byte[SaveUtil.SIZE_G5RAW] : (byte[])data.Clone();
            BAK        = (byte[])Data.Clone();
            Exportable = !Data.SequenceEqual(new byte[Data.Length]);

            // Get Version
            if (data == null)
            {
                Version = GameVersion.B2W2;
            }
            else if (versionOverride != GameVersion.Any)
            {
                Version = versionOverride;
            }
            else
            {
                Version = SaveUtil.getIsG5SAV(Data);
            }
            if (Version == GameVersion.Invalid)
            {
                return;
            }

            // First blocks are always the same position/size
            PCLayout       = 0x0;
            Box            = 0x400;
            Party          = 0x18E00;
            Trainer1       = 0x19400;
            WondercardData = 0x1C800;
            AdventureInfo  = 0x1D900;

            // Different Offsets for later blocks
            switch (Version)
            {
            case GameVersion.BW:
                BattleBox            = 0x20A00;
                Trainer2             = 0x21200;
                Daycare              = 0x20E00;
                PokeDex              = 0x21600;
                PokeDexLanguageFlags = PokeDex + 0x320;
                CGearInfoOffset      = 0x1C000;
                CGearDataOffset      = 0x52000;

                // Inventory offsets are the same for each game.
                OFS_PouchHeldItem = 0x18400; // 0x188D7
                OFS_PouchKeyItem  = 0x188D8; // 0x18A23
                OFS_PouchTMHM     = 0x18A24; // 0x18BD7
                OFS_PouchMedicine = 0x18BD8; // 0x18C97
                OFS_PouchBerry    = 0x18C98; // 0x18DBF
                LegalItems        = Legal.Pouch_Items_BW;
                LegalKeyItems     = Legal.Pouch_Key_BW;
                LegalTMHMs        = Legal.Pouch_TMHM_BW;
                LegalMedicine     = Legal.Pouch_Medicine_BW;
                LegalBerries      = Legal.Pouch_Berries_BW;

                Personal = PersonalTable.BW;
                break;

            case GameVersion.B2W2:     // B2W2
                BattleBox            = 0x20900;
                Trainer2             = 0x21100;
                EventConst           = 0x1FF00;
                EventFlag            = EventConst + 0x35E;
                Daycare              = 0x20D00;
                PokeDex              = 0x21400;
                PokeDexLanguageFlags = PokeDex + 0x328;     // forme flags size is + 8 from bw with new formes (therians)
                CGearInfoOffset      = 0x1C000;
                CGearDataOffset      = 0x52800;

                // Inventory offsets are the same for each game.
                OFS_PouchHeldItem = 0x18400; // 0x188D7
                OFS_PouchKeyItem  = 0x188D8; // 0x18A23
                OFS_PouchTMHM     = 0x18A24; // 0x18BD7
                OFS_PouchMedicine = 0x18BD8; // 0x18C97
                OFS_PouchBerry    = 0x18C98; // 0x18DBF
                LegalItems        = Legal.Pouch_Items_BW;
                LegalKeyItems     = Legal.Pouch_Key_B2W2;
                LegalTMHMs        = Legal.Pouch_TMHM_BW;
                LegalMedicine     = Legal.Pouch_Medicine_BW;
                LegalBerries      = Legal.Pouch_Berries_BW;

                Personal = PersonalTable.B2W2;
                break;
            }
            HeldItems = Legal.HeldItems_BW;
            getBlockInfo();

            if (!Exportable)
            {
                resetBoxes();
            }
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        public SAV1(byte[] data = null)
        {
            Data       = data == null ? new byte[SaveUtil.SIZE_G1RAW] : (byte[])data.Clone();
            BAK        = (byte[])Data.Clone();
            Exportable = !Data.SequenceEqual(new byte[Data.Length]);

            Version = data == null ? GameVersion.RBY : SaveUtil.getIsG1SAV(Data);
            if (Version == GameVersion.Invalid)
            {
                return;
            }

            Box = Data.Length;
            Array.Resize(ref Data, Data.Length + SIZE_RESERVED);
            Party = getPartyOffset(0);

            Japanese = SaveUtil.getIsG1SAVJ(data);
            Personal = PersonalTable.RBY;

            // Stash boxes after the save file's end.
            byte[] TempBox = new byte[SIZE_STOREDBOX];
            for (int i = 0; i < BoxCount; i++)
            {
                if (i < BoxCount / 2)
                {
                    Array.Copy(Data, 0x4000 + i * TempBox.Length, TempBox, 0, TempBox.Length);
                }
                else
                {
                    Array.Copy(Data, 0x6000 + (i - BoxCount / 2) * TempBox.Length, TempBox, 0, TempBox.Length);
                }
                PokemonList1 PL1 = new PokemonList1(TempBox, Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese);
                for (int j = 0; j < PL1.Pokemon.Length; j++)
                {
                    if (j < PL1.Count)
                    {
                        byte[] pkDat = new PokemonList1(PL1[j]).GetBytes();
                        pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + i * SIZE_BOX + j * SIZE_STORED);
                    }
                    else
                    {
                        byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)];
                        pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + i * SIZE_BOX + j * SIZE_STORED);
                    }
                }
            }

            Array.Copy(Data, Japanese ? 0x302D : 0x30C0, TempBox, 0, TempBox.Length);
            PokemonList1 curBoxPL = new PokemonList1(TempBox, Japanese ? PokemonList1.CapacityType.StoredJP : PokemonList1.CapacityType.Stored, Japanese);

            for (int i = 0; i < curBoxPL.Pokemon.Length; i++)
            {
                if (i < curBoxPL.Count)
                {
                    byte[] pkDat = new PokemonList1(curBoxPL[i]).GetBytes();
                    pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + CurrentBox * SIZE_BOX + i * SIZE_STORED);
                }
                else
                {
                    byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)];
                    pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + CurrentBox * SIZE_BOX + i * SIZE_STORED);
                }
            }

            byte[] TempParty = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Party, Japanese)];
            Array.Copy(Data, Japanese ? 0x2ED5 : 0x2F2C, TempParty, 0, TempParty.Length);
            PokemonList1 partyList = new PokemonList1(TempParty, PokemonList1.CapacityType.Party, Japanese);

            for (int i = 0; i < partyList.Pokemon.Length; i++)
            {
                if (i < partyList.Count)
                {
                    byte[] pkDat = new PokemonList1(partyList[i]).GetBytes();
                    pkDat.CopyTo(Data, getPartyOffset(i));
                }
                else
                {
                    byte[] pkDat = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)];
                    pkDat.CopyTo(Data, getPartyOffset(i));
                }
            }

            byte[] rawDC = new byte[0x38];
            Array.Copy(Data, Japanese ? 0x2CA7 : 0x2CF4, rawDC, 0, rawDC.Length);
            byte[] TempDaycare = new byte[PokemonList1.GetDataLength(PokemonList1.CapacityType.Single, Japanese)];
            TempDaycare[0] = rawDC[0];
            Array.Copy(rawDC, 1, TempDaycare, 2 + 1 + PKX.SIZE_1PARTY + StringLength, StringLength);
            Array.Copy(rawDC, 1 + StringLength, TempDaycare, 2 + 1 + PKX.SIZE_1PARTY, StringLength);
            Array.Copy(rawDC, 1 + 2 * StringLength, TempDaycare, 2 + 1, PKX.SIZE_1STORED);
            PokemonList1 daycareList = new PokemonList1(TempDaycare, PokemonList1.CapacityType.Single, Japanese);

            daycareList.GetBytes().CopyTo(Data, getPartyOffset(7));
            Daycare = getPartyOffset(7);

            // Enable Pokedex editing
            PokeDex = 0;

            if (!Exportable)
            {
                resetBoxes();
            }
        }
Exemplo n.º 8
0
        public SAV3(byte[] data = null, GameVersion versionOverride = GameVersion.Any)
        {
            Data       = data == null ? new byte[SaveUtil.SIZE_G3RAW] : (byte[])data.Clone();
            BAK        = (byte[])Data.Clone();
            Exportable = !Data.SequenceEqual(new byte[Data.Length]);

            if (data == null)
            {
                Version = GameVersion.FRLG;
            }
            else if (versionOverride != GameVersion.Any)
            {
                Version = versionOverride;
            }
            else
            {
                Version = SaveUtil.getIsG3SAV(Data);
            }
            if (Version == GameVersion.Invalid)
            {
                return;
            }

            int[] BlockOrder1 = new int[14];
            for (int i = 0; i < 14; i++)
            {
                BlockOrder1[i] = BitConverter.ToInt16(Data, i * 0x1000 + 0xFF4);
            }
            int zeroBlock1 = Array.IndexOf(BlockOrder1, 0);

            if (data.Length > SaveUtil.SIZE_G3RAWHALF)
            {
                int[] BlockOrder2 = new int[14];
                for (int i = 0; i < 14; i++)
                {
                    BlockOrder2[i] = BitConverter.ToInt16(Data, 0xE000 + i * 0x1000 + 0xFF4);
                }
                int zeroBlock2 = Array.IndexOf(BlockOrder2, 0);

                if (zeroBlock2 < 0)
                {
                    ActiveSAV = 0;
                }
                else if (zeroBlock1 < 0)
                {
                    ActiveSAV = 1;
                }
                else
                {
                    ActiveSAV = BitConverter.ToUInt32(Data, zeroBlock1 * 0x1000 + 0xFFC) >
                                BitConverter.ToUInt32(Data, zeroBlock2 * 0x1000 + 0xEFFC)
                    ? 0
                    : 1;
                }
                BlockOrder = ActiveSAV == 0 ? BlockOrder1 : BlockOrder2;
            }
            else
            {
                ActiveSAV  = 0;
                BlockOrder = BlockOrder1;
            }

            BlockOfs = new int[14];
            for (int i = 0; i < 14; i++)
            {
                BlockOfs[i] = Array.IndexOf(BlockOrder, i) * 0x1000 + ABO;
            }

            // Set up PC data buffer beyond end of save file.
            Box = Data.Length;
            Array.Resize(ref Data, Data.Length + SIZE_RESERVED); // More than enough empty space.

            // Copy chunk to the allocated location
            for (int i = 5; i < 14; i++)
            {
                int blockIndex = Array.IndexOf(BlockOrder, i);
                if (blockIndex == -1) // block empty
                {
                    continue;
                }
                Array.Copy(Data, blockIndex * 0x1000 + ABO, Data, Box + (i - 5) * 0xF80, chunkLength[i]);
            }

            switch (Version)
            {
            case GameVersion.RS:
                LegalKeyItems     = Legal.Pouch_Key_RS;
                OFS_PouchHeldItem = BlockOfs[1] + 0x0560;
                OFS_PouchKeyItem  = BlockOfs[1] + 0x05B0;
                OFS_PouchBalls    = BlockOfs[1] + 0x0600;
                OFS_PouchTMHM     = BlockOfs[1] + 0x0640;
                OFS_PouchBerry    = BlockOfs[1] + 0x0740;
                Personal          = PersonalTable.RS;
                break;

            case GameVersion.FRLG:
                LegalKeyItems     = Legal.Pouch_Key_FRLG;
                OFS_PouchHeldItem = BlockOfs[1] + 0x0310;
                OFS_PouchKeyItem  = BlockOfs[1] + 0x03B8;
                OFS_PouchBalls    = BlockOfs[1] + 0x0430;
                OFS_PouchTMHM     = BlockOfs[1] + 0x0464;
                OFS_PouchBerry    = BlockOfs[1] + 0x054C;
                Personal          = PersonalTable.FR;
                break;

            case GameVersion.E:
                LegalKeyItems     = Legal.Pouch_Key_E;
                OFS_PouchHeldItem = BlockOfs[1] + 0x0560;
                OFS_PouchKeyItem  = BlockOfs[1] + 0x05D8;
                OFS_PouchBalls    = BlockOfs[1] + 0x0650;
                OFS_PouchTMHM     = BlockOfs[1] + 0x0690;
                OFS_PouchBerry    = BlockOfs[1] + 0x0790;
                Personal          = PersonalTable.E;
                break;
            }
            LegalItems   = Legal.Pouch_Items_RS;
            LegalBalls   = Legal.Pouch_Ball_RS;
            LegalTMHMs   = Legal.Pouch_TMHM_RS;
            LegalBerries = Legal.Pouch_Berries_RS;

            HeldItems = Legal.HeldItems_RS;

            if (!Exportable)
            {
                resetBoxes();
            }
        }
Exemplo n.º 9
0
        public SAV3XD(byte[] data = null)
        {
            Data       = data == null ? new byte[SaveUtil.SIZE_G3XD] : (byte[])data.Clone();
            BAK        = (byte[])Data.Clone();
            Exportable = !Data.SequenceEqual(new byte[Data.Length]);

            if (SaveUtil.getIsG3XDSAV(Data) != GameVersion.XD)
            {
                return;
            }

            OriginalData = (byte[])Data.Clone();

            // Scan all 3 save slots for the highest counter
            for (int i = 0; i < SLOT_COUNT; i++)
            {
                int slotOffset  = SLOT_START + i * SLOT_SIZE;
                int SaveCounter = BigEndian.ToInt32(Data, slotOffset + 4);
                if (SaveCounter <= SaveCount)
                {
                    continue;
                }

                SaveCount = SaveCounter;
                SaveIndex = i;
            }

            // Decrypt most recent save slot
            {
                byte[] slot       = new byte[SLOT_SIZE];
                int    slotOffset = SLOT_START + SaveIndex * SLOT_SIZE;
                Array.Copy(Data, slotOffset, slot, 0, slot.Length);

                ushort[] keys = new ushort[4];
                for (int i = 0; i < keys.Length; i++)
                {
                    keys[i] = BigEndian.ToUInt16(slot, 8 + i * 2);
                }

                // Decrypt Slot
                Data = SaveUtil.DecryptGC(slot, 0x00010, 0x27FD8, keys);
            }

            // Get Offset Info
            ushort[] subLength = new ushort[16];
            for (int i = 0; i < 16; i++)
            {
                subLength[i]  = BigEndian.ToUInt16(Data, 0x20 + 2 * i);
                subOffsets[i] = BigEndian.ToUInt16(Data, 0x40 + 4 * i) | BigEndian.ToUInt16(Data, 0x40 + 4 * i + 2) << 16;
            }
            // Offsets are displaced by the 0xA8 savedata region
            Trainer1 = subOffsets[1] + 0xA8;
            Party    = Trainer1 + 0x30;
            Box      = subOffsets[2] + 0xA8;
            Daycare  = subOffsets[4] + 0xA8;
            Memo     = subOffsets[5] + 0xA8;
            Shadow   = subOffsets[7] + 0xA8;
            // Purifier = subOffsets[14] + 0xA8;

            StrategyMemo = new StrategyMemo(Data, Memo, xd: true);
            ShadowInfo   = new ShadowInfoTableXD(Data.Skip(Shadow).Take(subLength[7]).ToArray());

            OFS_PouchHeldItem = Trainer1 + 0x4C8;
            OFS_PouchKeyItem  = Trainer1 + 0x540;
            OFS_PouchBalls    = Trainer1 + 0x5EC;
            OFS_PouchTMHM     = Trainer1 + 0x62C;
            OFS_PouchBerry    = Trainer1 + 0x72C;
            OFS_PouchCologne  = Trainer1 + 0x7E4;
            OFS_PouchDisc     = Trainer1 + 0x7F0;

            LegalItems    = Legal.Pouch_Items_XD;
            LegalKeyItems = Legal.Pouch_Key_XD;
            LegalBalls    = Legal.Pouch_Ball_RS;
            LegalTMHMs    = Legal.Pouch_TM_RS; // not HMs
            LegalBerries  = Legal.Pouch_Berries_RS;
            LegalCologne  = Legal.Pouch_Cologne_CXD;
            LegalDisc     = Legal.Pouch_Disc_XD;

            Personal  = PersonalTable.RS;
            HeldItems = Legal.HeldItems_XD;

            if (!Exportable)
            {
                resetBoxes();
            }

            // Since PartyCount is not stored in the save file,
            // Count up how many party slots are active.
            for (int i = 0; i < 6; i++)
            {
                if (getPartySlot(getPartyOffset(i)).Species != 0)
                {
                    PartyCount++;
                }
            }
        }
Exemplo n.º 10
0
        public SAV3Colosseum(byte[] data = null)
        {
            Data       = data == null ? new byte[SaveUtil.SIZE_G3COLO] : (byte[])data.Clone();
            BAK        = (byte[])Data.Clone();
            Exportable = !Data.SequenceEqual(new byte[Data.Length]);

            if (SaveUtil.getIsG3COLOSAV(Data) != GameVersion.COLO)
            {
                return;
            }

            OriginalData = (byte[])Data.Clone();

            // Scan all 3 save slots for the highest counter
            for (int i = 0; i < SLOT_COUNT; i++)
            {
                int slotOffset  = SLOT_START + i * SLOT_SIZE;
                int SaveCounter = BigEndian.ToInt32(Data, slotOffset + 4);
                if (SaveCounter <= SaveCount)
                {
                    continue;
                }

                SaveCount = SaveCounter;
                SaveIndex = i;
            }

            // Decrypt most recent save slot
            {
                byte[] slot       = new byte[SLOT_SIZE];
                int    slotOffset = SLOT_START + SaveIndex * SLOT_SIZE;
                Array.Copy(Data, slotOffset, slot, 0, slot.Length);
                byte[] digest = new byte[20];
                Array.Copy(slot, SLOT_SIZE - 20, digest, 0, digest.Length);

                // Decrypt Slot
                Data = DecryptColosseum(slot, digest);
            }

            Trainer1          = 0x00078;
            Party             = 0x000A8;
            OFS_PouchHeldItem = 0x007F8;
            OFS_PouchKeyItem  = 0x00848;
            OFS_PouchBalls    = 0x008F4;
            OFS_PouchTMHM     = 0x00934;
            OFS_PouchBerry    = 0x00A34;
            OFS_PouchCologne  = 0x00AEC; // Cologne

            Box          = 0x00B90;
            Daycare      = 0x08170;
            Memo         = 0x082B0;
            StrategyMemo = new StrategyMemo(Data, Memo, xd: false);

            LegalItems    = Legal.Pouch_Items_COLO;
            LegalKeyItems = Legal.Pouch_Key_COLO;
            LegalBalls    = Legal.Pouch_Ball_RS;
            LegalTMHMs    = Legal.Pouch_TM_RS; // not HMs
            LegalBerries  = Legal.Pouch_Berries_RS;
            LegalCologne  = Legal.Pouch_Cologne_CXD;

            Personal  = PersonalTable.RS;
            HeldItems = Legal.HeldItems_COLO;

            if (!Exportable)
            {
                resetBoxes();
            }

            // Since PartyCount is not stored in the save file,
            // Count up how many party slots are active.
            for (int i = 0; i < 6; i++)
            {
                if (getPartySlot(getPartyOffset(i)).Species != 0)
                {
                    PartyCount++;
                }
            }
        }
Exemplo n.º 11
0
        public SAV2(byte[] data = null)
        {
            Data       = data == null ? new byte[SaveUtil.SIZE_G2RAW_U] : (byte[])data.Clone();
            BAK        = (byte[])Data.Clone();
            Exportable = !Data.SequenceEqual(new byte[Data.Length]);

            Version = data == null ? GameVersion.GSC : SaveUtil.getIsG2SAV(Data);
            if (Version == GameVersion.Invalid)
            {
                return;
            }

            Japanese = SaveUtil.getIsG2SAVJ(Data) != GameVersion.Invalid;
            if (Japanese && Data.Length < SaveUtil.SIZE_G2RAW_J)
            {
                Array.Resize(ref Data, SaveUtil.SIZE_G2RAW_J);
            }

            Box = Data.Length;
            Array.Resize(ref Data, Data.Length + SIZE_RESERVED);
            Party = getPartyOffset(0);

            Personal = Version == GameVersion.GS ? PersonalTable.GS : PersonalTable.C;

            getSAVOffsets();

            LegalItems    = Legal.Pouch_Items_GSC;
            LegalBalls    = Legal.Pouch_Ball_GSC;
            LegalKeyItems = Version == GameVersion.C ? Legal.Pouch_Key_C : Legal.Pouch_Key_GS;
            LegalTMHMs    = Legal.Pouch_TMHM_GSC;
            HeldItems     = Legal.HeldItems_GSC;

            // Stash boxes after the save file's end.
            byte[] TempBox = new byte[SIZE_STOREDBOX];
            for (int i = 0; i < BoxCount; i++)
            {
                if (i < (Japanese ? 6 : 7))
                {
                    Array.Copy(Data, 0x4000 + i * (TempBox.Length + 2), TempBox, 0, TempBox.Length);
                }
                else
                {
                    Array.Copy(Data, 0x6000 + (i - (Japanese ? 6 : 7)) * (TempBox.Length + 2), TempBox, 0, TempBox.Length);
                }
                PokemonList2 PL2 = new PokemonList2(TempBox, Japanese ? PokemonList2.CapacityType.StoredJP : PokemonList2.CapacityType.Stored, Japanese);
                for (int j = 0; j < PL2.Pokemon.Length; j++)
                {
                    if (j < PL2.Count)
                    {
                        byte[] pkDat = new PokemonList2(PL2[j]).GetBytes();
                        pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + i * SIZE_BOX + j * SIZE_STORED);
                    }
                    else
                    {
                        byte[] pkDat = new byte[PokemonList2.GetDataLength(PokemonList2.CapacityType.Single, Japanese)];
                        pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + i * SIZE_BOX + j * SIZE_STORED);
                    }
                }
            }

            Array.Copy(Data, CurrentBoxOffset, TempBox, 0, TempBox.Length);
            PokemonList2 curBoxPL = new PokemonList2(TempBox, Japanese ? PokemonList2.CapacityType.StoredJP : PokemonList2.CapacityType.Stored, Japanese);

            for (int i = 0; i < curBoxPL.Pokemon.Length; i++)
            {
                if (i < curBoxPL.Count)
                {
                    byte[] pkDat = new PokemonList2(curBoxPL[i]).GetBytes();
                    pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + CurrentBox * SIZE_BOX + i * SIZE_STORED);
                }
                else
                {
                    byte[] pkDat = new byte[PokemonList2.GetDataLength(PokemonList2.CapacityType.Single, Japanese)];
                    pkDat.CopyTo(Data, Data.Length - SIZE_RESERVED + CurrentBox * SIZE_BOX + i * SIZE_STORED);
                }
            }

            byte[] TempParty = new byte[PokemonList2.GetDataLength(PokemonList2.CapacityType.Party, Japanese)];
            Array.Copy(Data, PartyOffset, TempParty, 0, TempParty.Length);
            PokemonList2 partyList = new PokemonList2(TempParty, PokemonList2.CapacityType.Party, Japanese);

            for (int i = 0; i < partyList.Pokemon.Length; i++)
            {
                if (i < partyList.Count)
                {
                    byte[] pkDat = new PokemonList2(partyList[i]).GetBytes();
                    pkDat.CopyTo(Data, getPartyOffset(i));
                }
                else
                {
                    byte[] pkDat = new byte[PokemonList2.GetDataLength(PokemonList2.CapacityType.Single, Japanese)];
                    pkDat.CopyTo(Data, getPartyOffset(i));
                }
            }

            // Daycare currently undocumented for all Gen II games.

            // Enable Pokedex editing
            PokeDex = 0;

            if (!Exportable)
            {
                resetBoxes();
            }
        }