PKHeX.SAV_SecretBase.B_FAV2SAV C# (CSharp) Method

B_FAV2SAV() private method

private B_FAV2SAV ( object sender, EventArgs e ) : void
sender object
e System.EventArgs
return void
        private void B_FAV2SAV(object sender, EventArgs e)
        {
            // Write data back to save
            int index = LB_Favorite.SelectedIndex; // store for restoring
            if (!GB_PKM.Enabled && index > 0)
            { Util.Error("Sorry, no overwriting someone else's base with your own data."); return; }
            if (GB_PKM.Enabled && index == 0)
            { Util.Error("Sorry, no overwriting of your own base with someone else's."); return; }
            if (LB_Favorite.Items[index].ToString().Substring(LB_Favorite.Items[index].ToString().Length - 5, 5) == "Empty")
            { Util.Error("Sorry, no overwriting an empty base with someone else's."); return; }
            if (index < 0) return;
            int offset = fav_offset + 0x5400 + 0x25A;

            // Base Offset Changing
            if (index == 0)
                offset = fav_offset + 0x5400 + 0x326;
            else offset += 0x3E0 * index;

            string TrainerName = TB_FOT.Text;
            byte[] tr = Encoding.Unicode.GetBytes(TrainerName);
            Array.Resize(ref tr, 0x22); Array.Copy(tr, 0, sav, sv + offset + 0x218, 0x1A);

            string team1 = TB_FT1.Text;
            string team2 = TB_FT2.Text;
            byte[] t1 = Encoding.Unicode.GetBytes(team1);
            Array.Resize(ref t1, 0x22); Array.Copy(t1, 0, sav, sv + offset + 0x232 + 0x22 * 0, 0x22);
            byte[] t2 = Encoding.Unicode.GetBytes(team2);
            Array.Resize(ref t2, 0x22); Array.Copy(t2, 0, sav, sv + offset + 0x232 + 0x22 * 1, 0x22);

            string saying1 = TB_FSay1.Text;
            string saying2 = TB_FSay2.Text;
            string saying3 = TB_FSay3.Text;
            string saying4 = TB_FSay4.Text;
            byte[] s1 = Encoding.Unicode.GetBytes(saying1);
            Array.Resize(ref s1, 0x22); Array.Copy(s1, 0, sav, sv + offset + 0x276 + 0x22 * 0, 0x22);
            byte[] s2 = Encoding.Unicode.GetBytes(saying2);
            Array.Resize(ref s2, 0x22); Array.Copy(s2, 0, sav, sv + offset + 0x276 + 0x22 * 1, 0x22);
            byte[] s3 = Encoding.Unicode.GetBytes(saying3);
            Array.Resize(ref s3, 0x22); Array.Copy(s3, 0, sav, sv + offset + 0x276 + 0x22 * 2, 0x22);
            byte[] s4 = Encoding.Unicode.GetBytes(saying4);
            Array.Resize(ref s4, 0x22); Array.Copy(s4, 0, sav, sv + offset + 0x276 + 0x22 * 3, 0x22);

            int baseloc = (int)NUD_FBaseLocation.Value;
            if (baseloc < 3) baseloc = 0; // skip 1/2 baselocs as they are dummied out ingame.
            Array.Copy(BitConverter.GetBytes(baseloc), 0, sav, sv + offset, 2);

            TB_FOT.Text = TrainerName; TB_FSay1.Text = saying1; TB_FSay2.Text = saying2; TB_FSay3.Text = saying3; TB_FSay4.Text = saying4;

            // Copy back Objects
            for (int i = 0; i < 25; i++)
                for (int z = 0; z < 12; z++)
                    sav[sv + offset + 2 + 12 * i + z] = objdata[i, z];

            if (GB_PKM.Enabled) // Copy pkm data back in
            {
                saveFavPKM();
                for (int i = 0; i < 3; i++)
                    for (int z = 0; z < 0x34; z++)
                        sav[sv + offset + 0x32E + 0x34 * i + z] = pkmdata[i, z];
            }
            popFavorite();
            LB_Favorite.SelectedIndex = index;
        }