PKHeX.CodeGenerator.B_Diff_Click C# (CSharp) Method

B_Diff_Click() private method

private B_Diff_Click ( object sender, EventArgs e ) : void
sender object
e EventArgs
return void
        private void B_Diff_Click(object sender, EventArgs e)
        {
            string result = ""; 
            RTB_Code.Clear();
            byte[] cybersav = m_parent.cyberSAV;
            byte[] editedsav = m_parent.savefile;
            byte[] newcyber = new byte[m_parent.cyberSAV.Length];
            Array.Copy(editedsav, 0x5400, newcyber, 0, newcyber.Length);

            int boxoffset = 0x22600;
            if (m_parent.savegame_oras) boxoffset = 0x33000;

            if (!m_parent.cybergadget)
            {
               Array.Copy(editedsav, m_parent.savindex * 0x7F000 + 0x5400,
                          newcyber, 0, newcyber.Length);
            }

            int lines = 0;  // 65400
            for (int i = 0; i < newcyber.Length - 0x200; i += 4)
            {
                // Skip Party and Boxes
                if (i == 0x14200) i += (260 * 6 + 4); // +4 to skip over party count
                if (i == boxoffset) i += (232 * 30 * 31);
                if (BitConverter.ToUInt32(cybersav, i) == BitConverter.ToUInt32(newcyber, i)) continue;

                result += ((0x20000000 + i).ToString("X8") + " ");
                result += (BitConverter.ToUInt32(newcyber, i).ToString("X8") + Environment.NewLine);

                lines++;
                if ((lines % 128 == 0) && CHK_Break.Checked)
                {
                    result +=
                        (Environment.NewLine +
                         "--- Segment " + (lines / 128 + 1) + " ---" +
                         Environment.NewLine + Environment.NewLine);
                }
                if (lines > 10000) goto toomany;
            }

            // Loop Through Party
            for (int i = 0x14200; i < 0x14200 + 260 * 6; i+= 260)
            {
                byte[] newdata = new byte[260]; Array.Copy(newcyber, i, newdata, 0, 260);
                byte[] olddata = new byte[260]; Array.Copy(cybersav, i, olddata, 0, 260);
                if (newdata.SequenceEqual(olddata)) continue;

                for (int z = 0; z < newdata.Length; z += 4)
                {
                    result += ((0x20000000 + i + z).ToString("X8") + " ");
                    result += (BitConverter.ToUInt32(newdata, z).ToString("X8") + Environment.NewLine);

                    lines++;
                    if ((lines % 128 == 0) && CHK_Break.Checked)
                    {
                        result +=
                            (Environment.NewLine +
                             "--- Segment " + (lines / 128 + 1) + " ---" +
                             Environment.NewLine + Environment.NewLine);
                    }
                    if (lines > 10000) goto toomany;
                }
            }

            // Fix Party Count if Necessary
            if (cybersav[0x14818] != newcyber[0x14818])
            {
                result += ((0x00000000 + 0x14818).ToString("X8") + " ");
                result += (newcyber[0x14818].ToString("X8") + Environment.NewLine);

                lines++;
                if ((lines % 128 == 0) && CHK_Break.Checked)
                {
                    result +=
                        (Environment.NewLine +
                         "--- Segment " + (lines / 128 + 1) + " ---" +
                         Environment.NewLine + Environment.NewLine);
                }
                if (lines > 10000) goto toomany;
            }

            // Loop Through Boxes
            for (int i = boxoffset; i < boxoffset + (232 * 30 * 31); i += 232)
            {
                byte[] newdata = new byte[232]; Array.Copy(newcyber, i, newdata, 0, 232);
                byte[] olddata = new byte[232]; Array.Copy(cybersav, i, olddata, 0, 232);
                if (newdata.SequenceEqual(olddata)) continue;

                for (int z = 0; z < newdata.Length; z += 4)
                {
                    result += ((0x20000000 + i + z).ToString("X8") + " ");
                    result += (BitConverter.ToUInt32(newdata, z).ToString("X8") + Environment.NewLine);

                    lines++;
                    if ((lines % 128 == 0) && CHK_Break.Checked)
                    {
                        result +=
                            (Environment.NewLine +
                             "--- Segment " + (lines / 128 + 1) + " ---" +
                             Environment.NewLine + Environment.NewLine);
                    }
                    if (lines > 10000) goto toomany;
                }
            }

            if ((lines / 128 > 0) && CHK_Break.Checked)
            {
                Util.Alert(String.Format("{0} Code Segments.",
                           (1 + (lines / 128))),
                           String.Format("{0} Lines.", lines));
            }
            RTB_Code.Text = result;
            return;

        toomany:
            {
                Util.Alert("Too many differences detected.",
                           "Export your save instead.");
            }
        }