예제 #1
0
파일: PKX.cs 프로젝트: kwsch/pk2pk
 internal static string getFileName(PK6 pk6)
 {
     return
         $"{pk6.Species.ToString("000")}{(pk6.IsShiny ? " ★" : "")} - {pk6.Nickname} - {pk6.Checksum.ToString("X4")}{pk6.EncryptionConstant.ToString("X8")}.pk6";
 }
예제 #2
0
파일: PKX.cs 프로젝트: kwsch/pk2pk
 internal static ushort[] getStats(PK6 pk6)
 {
     return getStats(pk6.Species, pk6.Stat_Level, pk6.Nature, pk6.AltForm,
         pk6.EV_HP, pk6.EV_ATK, pk6.EV_DEF, pk6.EV_SPA, pk6.EV_SPD, pk6.EV_SPE,
         pk6.IV_HP, pk6.IV_ATK, pk6.IV_DEF, pk6.IV_SPA, pk6.IV_SPD, pk6.IV_SPE);
 }
예제 #3
0
파일: Form1.cs 프로젝트: kwsch/pk2pk
        private void convert(string path)
        {
            FileInfo fi = new FileInfo(path);
            string filename = Path.GetFileNameWithoutExtension(path);
            string foldername = Path.GetDirectoryName(path);
            string extension = Path.GetExtension(path);
            long len = fi.Length;
            byte[] data;
            byte[] newdata = new byte[136];
            int game;

            if ((len == PK3.SIZE_STORED || len == PK3.SIZE_PARTY) && RB_I3.Checked)
            {
                game = 4;
                data = File.ReadAllBytes(path);
                if (!PKX.verifychk(data))
                    goto invalidchk;
                newdata = new PK3(data).convertToPK4().Data;
                if (RB_O5.Checked)
                {
                    newdata = new PK4(newdata).convertToPK5().Data;
                    game = 5;
                }
                else if (RB_O6.Checked)
                {
                    newdata = new PK4(newdata).convertToPK5().Data;
                    newdata = new PK5(newdata).convertToPK6().Data;
                    game = 6;
                }
            }
            else if ((len == PK4.SIZE_STORED || len == PK4.SIZE_PARTY) && RB_I4.Checked)
            {
                game = 5;
                data = File.ReadAllBytes(path);
                PKM.checkEncrypted(ref data);
                if (!PKX.verifychk(data))
                    goto invalidchk;
                newdata = new PK4(data).convertToPK5().Data;
                if (RB_O6.Checked)
                {
                    newdata = new PK5(newdata).convertToPK6().Data;
                    game = 6;
                }
            }
            else if ((len == PK5.SIZE_STORED || len == PK5.SIZE_PARTY) && RB_I5.Checked)
            {
                game = 6;
                data = File.ReadAllBytes(path);
                PKM.checkEncrypted(ref data);
                if (!PKX.verifychk(data))
                    goto invalidchk;
                if (BitConverter.ToUInt32(data, 0x44) != 0) // if PTHGSS met data exists
                    data = new PK4(data).convertToPK5().Data;

                newdata = new PK5(data).convertToPK6().Data;
            }
            else
            {
                RTB_Output.AppendText($"Invalid file supplied. ({filename}{extension})" + Environment.NewLine);
                goto quit;
            }

            invalidchk:
            {
                if (!PKX.verifychk(data))
                {
                    RTB_Output.AppendText($"Invalid checksum. Is the file encrypted? ({filename}{extension})" + Environment.NewLine);
                    goto quit;
                }
            }

            // Output
            string ext;
            if (RB_O6.Checked)
                ext = ".pk6";
            else if (RB_O5.Checked)
                ext = ".pk5";
            else ext = ".pk4";
            if (RB_PKM.Checked)
                ext = ".pkm";
            if (RB_PKM.Checked && RB_O6.Checked)
                ext = ".pkx";
            string newname = Path.Combine(foldername, filename + ext);
            if (newname == path)
                newname = Path.Combine(foldername, filename + " - " + game + "th" + ext);
            File.WriteAllBytes(newname,newdata);

            var pk6 = new PK6();
            if (game == 4)
                pk6 = new PK4(newdata).convertToPK5().convertToPK6();
            else if (game == 5)
                pk6 = new PK5(newdata).convertToPK6();
            else
                pk6 = new PK6(newdata);

            RTB_Output.AppendText(
                $"{pk6.Nickname} converted to Gen {game} @ {pk6.OT_Name} ({pk6.TID.ToString("00000")}/{pk6.SID.ToString("00000")}){Environment.NewLine}");
            quit:
            {
                RTB_Output.AppendText("----------" + Environment.NewLine);
                RTB_Output.SelectionStart = RTB_Output.Text.Length;
                RTB_Output.ScrollToCaret();
            }
        }