Esempio n. 1
0
        public SAV2(byte[] data, GameVersion versionOverride = GameVersion.Any) : base(data)
        {
            Version  = versionOverride != GameVersion.Any ? versionOverride : SaveUtil.GetIsG2SAV(Data);
            Japanese = SaveUtil.GetIsG2SAVJ(Data) != GameVersion.Invalid;
            if (Version != GameVersion.C && !Japanese)
            {
                Korean = SaveUtil.GetIsG2SAVK(Data) != GameVersion.Invalid;
            }

            Offsets  = new SAV2Offsets(this);
            Personal = Version == GameVersion.GS ? PersonalTable.GS : PersonalTable.C;
            Initialize();
        }
Esempio n. 2
0
        public SAV2(byte[] data, GameVersion versionOverride = GameVersion.Any) : base(data)
        {
            Version = versionOverride != GameVersion.Any ? versionOverride : SaveUtil.GetIsG2SAV(Data);
            if (Version == GameVersion.Invalid)
            {
                return;
            }
            Japanese = SaveUtil.GetIsG2SAVJ(Data) != GameVersion.Invalid;
            if (!Japanese)
            {
                Korean = SaveUtil.GetIsG2SAVK(Data) != GameVersion.Invalid;
            }

            Offsets = new SAV2Offsets(this);
            Initialize();
        }
Esempio n. 3
0
        public SAV2(byte[] data = null, GameVersion versionOverride = GameVersion.Any)
        {
            Data       = data ?? new byte[SaveUtil.SIZE_G2RAW_U];
            BAK        = (byte[])Data.Clone();
            Exportable = !IsRangeEmpty(0, Data.Length);

            if (data == null)
            {
                Version = GameVersion.C;
            }
            else if (versionOverride != GameVersion.Any)
            {
                Version = versionOverride;
            }
            else
            {
                Version = SaveUtil.GetIsG2SAV(Data);
            }

            if (Version == GameVersion.Invalid)
            {
                return;
            }

            Japanese = SaveUtil.GetIsG2SAVJ(Data) != GameVersion.Invalid;
            if (!Japanese)
            {
                Korean = SaveUtil.GetIsG2SAVK(Data) != GameVersion.Invalid;
            }

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

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

            Offsets = new SAV2Offsets(this);

            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.
            int splitAtIndex = (Japanese ? 6 : 7);
            int stored       = SIZE_STOREDBOX;
            int baseDest     = Data.Length - SIZE_RESERVED;
            var capacity     = Japanese ? PokeListType.StoredJP : PokeListType.Stored;

            for (int i = 0; i < BoxCount; i++)
            {
                int ofs     = GetBoxRawDataOffset(i, splitAtIndex);
                var box     = GetData(ofs, stored);
                var boxDest = baseDest + (i * SIZE_BOX);
                var boxPL   = new PokeList2(box, capacity, Japanese);
                for (int j = 0; j < boxPL.Pokemon.Length; j++)
                {
                    var dest  = boxDest + (j * SIZE_STORED);
                    var pkDat = (j < boxPL.Count)
                        ? new PokeList2(boxPL[j]).Write()
                        : new byte[PokeList2.GetDataLength(PokeListType.Single, Japanese)];
                    pkDat.CopyTo(Data, dest);
                }
            }

            var current  = GetData(Offsets.CurrentBox, stored);
            var curBoxPL = new PokeList2(current, capacity, Japanese);
            var curDest  = baseDest + (CurrentBox * SIZE_BOX);

            for (int i = 0; i < curBoxPL.Pokemon.Length; i++)
            {
                var dest  = curDest + (i * SIZE_STORED);
                var pkDat = i < curBoxPL.Count
                    ? new PokeList2(curBoxPL[i]).Write()
                    : new byte[PokeList2.GetDataLength(PokeListType.Single, Japanese)];
                pkDat.CopyTo(Data, dest);
            }

            var party   = GetData(Offsets.Party, SIZE_STOREDPARTY);
            var partyPL = new PokeList2(party, PokeListType.Party, Japanese);

            for (int i = 0; i < partyPL.Pokemon.Length; i++)
            {
                var dest  = GetPartyOffset(i);
                var pkDat = i < partyPL.Count
                    ? new PokeList2(partyPL[i]).Write()
                    : new byte[PokeList2.GetDataLength(PokeListType.Single, Japanese)];
                pkDat.CopyTo(Data, dest);
            }

            if (Offsets.Daycare >= 0)
            {
                int offset = Offsets.Daycare;

                DaycareFlags[0] = Data[offset]; offset++;
                var pk1      = ReadPKMFromOffset(offset);    // parent 1
                var daycare1 = new PokeList2(pk1);
                offset         += (StringLength * 2) + 0x20; // nick/ot/pkm
                DaycareFlags[1] = Data[offset]; offset++;
                byte steps = Data[offset]; offset++;
                byte BreedMotherOrNonDitto = Data[offset]; offset++;
                var  pk2      = ReadPKMFromOffset(offset);       // parent 2
                var  daycare2 = new PokeList2(pk2);
                offset += (StringLength * 2) + PKX.SIZE_2STORED; // nick/ot/pkm
                var pk3 = ReadPKMFromOffset(offset);             // egg!
                pk3.IsEgg = true;
                var daycare3 = new PokeList2(pk3);

                daycare1.Write().CopyTo(Data, GetPartyOffset(7 + (0 * 2)));
                daycare2.Write().CopyTo(Data, GetPartyOffset(7 + (1 * 2)));
                daycare3.Write().CopyTo(Data, GetPartyOffset(7 + (2 * 2)));
                Daycare = Offsets.Daycare;
            }

            // Enable Pokedex editing
            PokeDex   = 0;
            EventFlag = Offsets.EventFlag;

            if (!Exportable)
            {
                ClearBoxes();
            }
        }
Esempio n. 4
0
        public SAV2(byte[] data = null, GameVersion versionOverride = GameVersion.Any)
        {
            Data       = data == null ? new byte[SaveUtil.SIZE_G2RAW_U] : (byte[])data.Clone();
            BAK        = (byte[])Data.Clone();
            Exportable = !Data.SequenceEqual(new byte[Data.Length]);

            if (data == null)
            {
                Version = GameVersion.C;
            }
            else if (versionOverride != GameVersion.Any)
            {
                Version = versionOverride;
            }
            else
            {
                Version = 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);
            }
            if (!Japanese)
            {
                Korean = SaveUtil.GetIsG2SAVK(Data) != GameVersion.Invalid;
            }

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

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

            Offsets = new SAV2Offsets(this);

            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, Offsets.CurrentBox, 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, Offsets.Party, 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)
            {
                ClearBoxes();
            }
        }
Esempio n. 5
0
        public SAV2(byte[] data = null, GameVersion versionOverride = GameVersion.Any)
        {
            Data       = data ?? new byte[SaveUtil.SIZE_G2RAW_U];
            BAK        = (byte[])Data.Clone();
            Exportable = !IsRangeEmpty(0, Data.Length);

            if (data == null)
            {
                Version = GameVersion.C;
            }
            else if (versionOverride != GameVersion.Any)
            {
                Version = versionOverride;
            }
            else
            {
                Version = SaveUtil.GetIsG2SAV(Data);
            }

            if (Version == GameVersion.Invalid)
            {
                return;
            }

            Japanese = SaveUtil.GetIsG2SAVJ(Data) != GameVersion.Invalid;
            if (!Japanese)
            {
                Korean = SaveUtil.GetIsG2SAVK(Data) != GameVersion.Invalid;
            }

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

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

            Offsets = new SAV2Offsets(this);

            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, Offsets.CurrentBox, 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, Offsets.Party, 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.
            if (Offsets.Daycare >= 0)
            {
                int offset = Offsets.Daycare;

                DaycareFlags[0] = Data[offset]; offset++;
                var pk1      = ReadPKMFromOffset(offset);  // parent 1
                var daycare1 = new PokemonList2(pk1);
                offset         += StringLength * 2 + 0x20; // nick/ot/pkm
                DaycareFlags[1] = Data[offset]; offset++;
                byte steps = Data[offset]; offset++;
                byte BreedMotherOrNonDitto = Data[offset]; offset++;
                var  pk2      = ReadPKMFromOffset(offset);     // parent 2
                var  daycare2 = new PokemonList2(pk2);
                offset += StringLength * 2 + PKX.SIZE_2STORED; // nick/ot/pkm
                var pk3 = ReadPKMFromOffset(offset);           // egg!
                pk3.IsEgg = true;
                var daycare3 = new PokemonList2(pk3);

                daycare1.GetBytes().CopyTo(Data, GetPartyOffset(7 + (0 * 2)));
                daycare2.GetBytes().CopyTo(Data, GetPartyOffset(7 + (1 * 2)));
                daycare3.GetBytes().CopyTo(Data, GetPartyOffset(7 + (2 * 2)));
                Daycare = Offsets.Daycare;
            }

            // Enable Pokedex editing
            PokeDex   = 0;
            EventFlag = Offsets.EventFlag;

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