示例#1
0
        private void LegalizeActive()
        {
            var pk = PKMEditor.PreparePKM();
            var la = new LegalityAnalysis(pk);

            if (la.Valid)
            {
                return; // already valid, don't modify it
            }
            var sav    = SaveFileEditor.SAV;
            var result = sav.Legalize(pk);

            // let's double check

            la = new LegalityAnalysis(result);
            if (!la.Valid)
            {
                WinFormsUtil.Error("Unable to make the Active Pokemon legal!");
                return;
            }

            PKMEditor.PopulateFields(result);
            WinFormsUtil.Alert("Legalized Active Pokemon!");
        }
示例#2
0
        private void B_ReadRAM_Click(object sender, EventArgs e)
        {
            var txt    = RamOffset.Text;
            var offset = Util.GetHexValue64(txt);
            var valid  = int.TryParse(RamSize.Text, out int size);

            if (offset.ToString("X16") != txt.ToUpper().PadLeft(16, '0') || !valid)
            {
                WinFormsUtil.Alert("Make sure that the RAM offset is a hex string and the size is a valid integer");
                return;
            }

            try
            {
                byte[] result;
                if (Remote.Bot.com is not ICommunicatorNX cnx)
                {
                    result = Remote.ReadRAM(offset, size);
                }
                else if (RB_Main.Checked)
                {
                    result = cnx.ReadBytesMain(offset, size);
                }
                else if (RB_Absolute.Checked)
                {
                    result = cnx.ReadBytesAbsolute(offset, size);
                }
                else
                {
                    result = Remote.ReadRAM(offset, size);
                }

                bool blockview = (ModifierKeys & Keys.Control) == Keys.Control;
                PKM? pkm       = null;
                if (blockview)
                {
                    pkm = SAV.SAV.GetDecryptedPKM(result);
                    if (!pkm.ChecksumValid)
                    {
                        blockview = false;
                    }
                }

                using var form = new SimpleHexEditor(result, Remote.Bot, offset, GetRWMethod());
                var loadgrid = blockview && ReflectUtil.GetPropertiesCanWritePublicDeclared(pkm !.GetType()).Count() > 1;
                if (loadgrid)
                {
                    form.PG_BlockView.Visible        = true;
                    form.PG_BlockView.SelectedObject = pkm;
                }
                var res = form.ShowDialog();
                if (res != DialogResult.OK)
                {
                    return;
                }

                if (loadgrid)
                {
                    PKM pk       = pkm !;
                    var pkmbytes = RamOffsets.WriteBoxData(Remote.Bot.Version) ? pk.EncryptedBoxData : pk.EncryptedPartyData;
                    if (pkmbytes.Length == Remote.Bot.SlotSize)
                    {
                        form.Bytes = pkmbytes;
                    }
                    else
                    {
                        form.Bytes = result;
                        WinFormsUtil.Error("Size mismatch. Please report this issue on the discord server.");
                    }
                }

                var modifiedRAM = form.Bytes;
                if (Remote.Bot.com is not ICommunicatorNX nx)
                {
                    Remote.WriteRAM(offset, modifiedRAM);
                }
示例#3
0
        private void B_Connect_Click(object sender, EventArgs e)
        {
            try
            {
                // Enable controls
                B_Connect.Enabled = TB_IP.Enabled = TB_Port.Enabled = false;
                groupBox1.Enabled = groupBox2.Enabled = groupBox3.Enabled = true;
                var ConnectionEstablished = false;
                var validversions         = RamOffsets.GetValidVersions(SAV.SAV).Reverse().ToArray();
                var currver = validversions[0];
                foreach (var version in validversions)
                {
                    Remote.Bot = new PokeSysBotMini(version, CurrentInjectionType)
                    {
                        com = { IP = TB_IP.Text, Port = int.Parse(TB_Port.Text) },
                    };
                    Remote.Bot.com.Connect();

                    var data = Remote.Bot.ReadSlot(1, 1);
                    var pkm  = SAV.SAV.GetDecryptedPKM(data);
                    if (pkm.ChecksumValid)
                    {
                        ConnectionEstablished = true;
                        currver = version;
                        if (Remote.Bot.com is IPokeBlocks)
                        {
                            var cblist = GetSortedBlockList(version).ToArray();
                            if (cblist.Length > 0)
                            {
                                groupBox5.Enabled = true;
                                CB_BlockName.Items.AddRange(cblist);
                                CB_BlockName.SelectedIndex = 0;
                            }
                        }
                        break;
                    }
                }

                if (!ConnectionEstablished)
                {
                    Remote.Bot = new PokeSysBotMini(currver, CurrentInjectionType)
                    {
                        com = { IP = TB_IP.Text, Port = int.Parse(TB_Port.Text) },
                    };
                    Remote.Bot.com.Connect();
                    Text += $" Unknown Version (Forced: {currver})";
                }
                else
                {
                    Text += $" Detected Version: {currver}";
                }

                if (Remote.Bot.com is ICommunicatorNX)
                {
                    groupBox4.Enabled = groupBox6.Enabled = true;
                }

                // Load current box
                Remote.ReadBox(SAV.CurrentBox);

                // Set Trainer Data
                SetTrainerData(SAV.SAV);
            }
            // Console might be disconnected...
            catch (Exception ex)
            {
                WinFormsUtil.Error(ex.Message);
            }
        }