Exemplo n.º 1
2
        private void openFile(byte[] input, string path, string ext)
        {
            #region Powersaves Read-Only Conversion
            if (input.Length == 0x10009C) // Resize to 1MB
            {
                Array.Copy(input, 0x9C, input, 0, 0x100000);
                Array.Resize(ref input, 0x100000);
            }
            #endregion
            #region Saves
            if (SAV6.SizeValid(input.Length) && BitConverter.ToUInt32(input, input.Length - 0x1F0) == SAV6.BEEF)
                openMAIN(input, path);
            // Verify the Data Input Size is Proper
            else if (input.Length == 0x100000)
            {
                if (openXOR(input, path)) // Check if we can load the save via xorpad
                    return; // only if a save is loaded we abort
                if (BitConverter.ToUInt64(input, 0x10) != 0) // encrypted save
                { Util.Error("PKHeX only edits decrypted save files." + Environment.NewLine + "This save file is not decrypted.", path); return; }
                
                DialogResult sdr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Press Yes to load the sav at 0x3000", "Press No for the one at 0x82000");
                if (sdr == DialogResult.Cancel)
                    return;
                int savshift = sdr == DialogResult.Yes ? 0 : 0x7F000;
                byte[] psdata = input.Skip(0x5400 + savshift).Take(SAV6.SIZE_ORAS).ToArray();
                if (BitConverter.ToUInt32(psdata, psdata.Length - 0x1F0) != SAV6.BEEF)
                    Array.Resize(ref psdata, SAV6.SIZE_XY);
                if (BitConverter.ToUInt32(psdata, psdata.Length - 0x1F0) != SAV6.BEEF)
                { Util.Error("The data file is not a valid save file", path); return; }

                openMAIN(psdata, path);
            }
            #endregion
            #region PK6/EK6
            else if ((input.Length == PK6.SIZE_PARTY || input.Length == PK6.SIZE_STORED) && ext != ".pgt")
            {
                // Check if Input is PKX
                if (new[] {".pk6", ".ek6", ".pkx", ".ekx", ""}.Contains(ext))
                {
                    // Check if Encrypted before Loading
                    populateFields(new PK6(BitConverter.ToUInt16(input, 0xC8) == 0 && BitConverter.ToUInt16(input, 0x58) == 0 ? input : PKX.decryptArray(input)));
                }
                else
                    Util.Error("Unable to recognize file." + Environment.NewLine + "Only valid .pk* .ek* .bin supported.",
                        $"File Loaded:{Environment.NewLine}{path}");
            }
            #endregion
            #region PK3/PK4/PK5 Conversion
            else if (new[] { PK3.SIZE_PARTY, PK3.SIZE_STORED, PK4.SIZE_PARTY, PK4.SIZE_STORED, PK5.SIZE_PARTY }.Contains(input.Length))
            {
                if (!PKX.verifychk(input)) Util.Error("Invalid File (Checksum Error)");
                try // to convert g5pkm
                {
                    populateFields(Converter.ConvertPKMtoPK6(input));
                }
                catch
                {
                    populateFields(new PK6());
                    Util.Error("Attempted to load previous generation PKM.", "Conversion failed.");
                }
            }
            #endregion
            #region Box Data
            else if ((input.Length == PK6.SIZE_STORED * 30 || input.Length == PK6.SIZE_STORED * 30 * 31) && BitConverter.ToUInt16(input, 4) == 0 && BitConverter.ToUInt32(input, 8) > 0)
            {
                int baseOffset = SAV.Box + PK6.SIZE_STORED * 30 * (input.Length == PK6.SIZE_STORED * 30 ? CB_BoxSelect.SelectedIndex : 0);
                for (int i = 0; i < input.Length / PK6.SIZE_STORED; i++)
                {
                    byte[] data = input.Skip(PK6.SIZE_STORED * i).Take(PK6.SIZE_STORED).ToArray();
                    SAV.setEK6Stored(data, baseOffset + i * PK6.SIZE_STORED);
                }
                setPKXBoxes();
                Util.Alert("Box Binary loaded.");
            }
            #endregion
            #region Battle Video
            else if (input.Length == 0x2E60 && BitConverter.ToUInt64(input, 0xE18) != 0 && BitConverter.ToUInt16(input, 0xE12) == 0)
            {
                if (Util.Prompt(MessageBoxButtons.YesNo, "Load Batte Video Pokémon data to " + CB_BoxSelect.Text + "?", "The first 24 slots will be overwritten.") != DialogResult.Yes)
                    return;

                DialogResult noSet = Util.Prompt(MessageBoxButtons.YesNoCancel, "Loading overrides:",
                    "Yes - Modify .pk6 when set to SAV" + Environment.NewLine +
                    "No - Don't modify .pk6" + Environment.NewLine +
                    "Cancel - Use current settings (" + (Menu_ModifyPK6.Checked ? "Yes" : "No") + ")");
                bool? noSetb = noSet == DialogResult.Yes ? true : (noSet == DialogResult.No ? (bool?)false : null);

                for (int i = 0; i < 24; i++)
                {
                    byte[] data = input.Skip(0xE18 + PK6.SIZE_PARTY * i + i / 6 * 8).Take(PK6.SIZE_STORED).ToArray();
                    int offset = SAV.Box + i*PK6.SIZE_STORED + CB_BoxSelect.SelectedIndex*30*PK6.SIZE_STORED;
                    SAV.setEK6Stored(data, offset, noSetb);
                }
                setPKXBoxes();
            }
            #endregion
            #region Wondercard
            else if ((input.Length == WC6.Size && ext == ".wc6") || (input.Length == WC6.SizeFull && ext == ".wc6full"))
            {
                if (input.Length == WC6.SizeFull) // Take bytes at end = WC6 size.
                    input = input.Skip(WC6.SizeFull - WC6.Size).ToArray();
                if (ModifierKeys == Keys.Control && SAV.PokeDex > -1)
                    new SAV_Wondercard(input).ShowDialog();
                else
                {
                    PK6 pk = new WC6(input).convertToPK6(SAV);
                    if (pk == null || pk.Species == 0 || pk.Species > 721)
                    {
                        Util.Error("Failed to convert Wondercard.",
                            pk == null ? "Not a Pokémon Wondercard." : "Invalid species.");
                        return;
                    }
                    populateFields(pk);
                }
            }
            else if (input.Length == PGF.Size && ext == ".pgf")
            {
                PK5 pk = new PGF(input).convertToPK5(SAV);
                if (pk == null || pk.Species == 0 || pk.Species > 721)
                {
                    Util.Error("Failed to convert PGF.",
                        pk == null ? "Not a Pokémon PGF." : "Invalid species.");
                    return;
                }
                populateFields(Converter.ConvertPKMtoPK6(pk.Data));
            }
            else if (input.Length == PGT.Size && ext == ".pgt")
            {
                PGT pgt = new PGT(input);
                PK4 pk = pgt.convertToPK4(SAV);
                if (pk == null || pk.Species == 0 || pk.Species > 721)
                {
                    Util.Error("Failed to convert PGT.",
                        pk == null ? "Not a Pokémon PGT." : "Invalid species.");
                    return;
                }
                populateFields(Converter.ConvertPKMtoPK6(pk.Data));
            }
            else if (input.Length == PCD.Size && ext == ".pcd")
            {
                PCD pcd = new PCD(input);
                PGT pgt = pcd.Gift;
                PK4 pk = pgt.convertToPK4(SAV);
                if (pk == null || pk.Species == 0 || pk.Species > 721)
                {
                    Util.Error("Failed to convert PCD.",
                        pk == null ? "Not a Pokémon PCD." : "Invalid species.");
                    return;
                }
                populateFields(Converter.ConvertPKMtoPK6(pk.Data));
            }
            #endregion
            else
                Util.Error("Attempted to load an unsupported file type/size.",
                    $"File Loaded:{Environment.NewLine}{path}",
                    $"File Size:{Environment.NewLine}{input.Length} bytes (0x{input.Length.ToString("X4")})");
        }
Exemplo n.º 2
0
        internal const int Size = 0x358; // 856

        #endregion Fields

        #region Constructors

        public PCD(byte[] data = null)
        {
            Data = (byte[])(data?.Clone() ?? new byte[Size]);

            byte[] giftData = new byte[PGT.Size];
            Array.Copy(Data, 0, giftData, 0, PGT.Size);
            Gift = new PGT(giftData);

            Information = new byte[Data.Length - PGT.Size];
            Array.Copy(Data, PGT.Size, Information, 0, Information.Length);
        }
Exemplo n.º 3
0
        public PCD(byte[] data = null)
        {
            Data = (byte[])(data?.Clone() ?? new byte[Size]);

            byte[] giftData = new byte[PGT.Size];
            Array.Copy(Data, 0, giftData, 0, PGT.Size);
            Gift = new PGT(giftData);

            Information = new byte[Data.Length - PGT.Size];
            Array.Copy(Data, PGT.Size, Information, 0, Information.Length);
        }