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 SysBotMini) { groupBox4.Enabled = true; } break; } if (!ConnectionEstablished) { Remote.Bot.com.Disconnect(); } } if (!ConnectionEstablished) { Remote.Bot = new PokeSysBotMini(currver, CurrentInjectionType) { com = { IP = TB_IP.Text, Port = int.Parse(TB_Port.Text) } }; Remote.Bot.com.Connect(); } // Load current box Remote.ReadBox(SAV.CurrentBox); // Set Trainer Data SetTrainerData(SAV.SAV, currver); } #pragma warning disable CA1031 // Do not catch general exception types // Console might be disconnected... catch (Exception ex) #pragma warning restore CA1031 // Do not catch general exception types { WinFormsUtil.Error(ex.Message); } }
protected override void AddPluginControl(ToolStripDropDownItem modmenu) { var c1 = new ToolStripMenuItem(Name) { Image = Resources.wifi }; c1.Click += (_, _) => { var sav = SaveFileEditor.SAV; if (!RamOffsets.IsLiveHeXSupported(sav)) { WinFormsUtil.Error("Must have a 3DS or Switch main line game save file currently loaded."); return; } var editor = WinFormsUtil.FirstFormOfType <LiveHeXUI>(); if (editor == null) { editor = new LiveHeXUI(SaveFileEditor, PKMEditor); editor.Show(); } else { editor.Focus(); // WinFormsUtil.Alert("LiveHeX already open!"); } }; c1.Name = "Menu_LiveHeX"; modmenu.DropDownItems.Add(c1); }
public LiveHeXController(ISaveFileProvider boxes, IPKMView editor, InjectorCommunicationType ict) { SAV = boxes; Editor = editor; var ValidVers = RamOffsets.GetValidVersions(boxes.SAV); Bot = new PokeSysBotMini(ValidVers[0], ict); }
public void WriteActiveSlot(int box, int slot) { var pkm = Editor.PreparePKM(); pkm.ResetPartyStats(); var data = RamOffsets.WriteBoxData(Bot.Version) ? pkm.EncryptedBoxData : pkm.EncryptedPartyData; Bot.SendSlot(data, box, slot); }
public void ReadBox(int box) { var sav = SAV.SAV; var len = SAV.SAV.BoxSlotCount * (RamOffsets.GetSlotSize(Bot.Version) + RamOffsets.GetGapSize(Bot.Version)); var data = Bot.ReadBox(box, len); sav.SetBoxBinary(data, box); SAV.ReloadSlots(); }
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 currver = LiveHeXVersion.SWSH_Rigel1; var validversions = RamOffsets.GetValidVersions(SAV.SAV); foreach (LiveHeXVersion ver in validversions) { Remote.Bot = new PokeSysBotMini(ver); Remote.Bot.IP = TB_IP.Text; Remote.Bot.Port = int.Parse(TB_Port.Text); Remote.Bot.Connect(); var data = Remote.Bot.ReadSlot(1, 1); var pkm = PKMConverter.GetPKMfromBytes(data); if (pkm != null && pkm.ChecksumValid && pkm.Species > -1) { ConnectionEstablished = true; currver = ver; break; } if (Remote.Bot.Connected) { Remote.Bot.Disconnect(); } } if (!ConnectionEstablished) { Remote.Bot = new PokeSysBotMini(currver); Remote.Bot.IP = TB_IP.Text; Remote.Bot.Port = int.Parse(TB_Port.Text); Remote.Bot.Connect(); } // Load current box Remote.ReadBox(SAV.CurrentBox); // Set Trainer Data SetTrainerData(SAV.SAV, currver); } catch (Exception ex) { WinFormsUtil.Error(ex.Message); } }
public IEnumerable <string> GetSortedBlockList() { var offsets = RamOffsets.GetOffsets(Remote.Bot.Version); if (offsets == null) { return(new List <string>()); } var aType = offsets.GetType(); var props = aType.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.DeclaredOnly); var ofType = props.Where(fi => typeof(uint).IsAssignableFrom(fi.FieldType)); var retval = ofType.ToDictionary(z => z.Name, x => (uint)x.GetValue(offsets)); return(retval.Where(z => z.Value != 0).Select(z => z.Key).OrderBy(z => z)); }
private void SetTrainerData(SaveFile sav, LiveHeXVersion lv) { var size = RamOffsets.GetTrainerBlockSize(lv); var ofs = RamOffsets.GetTrainerBlockOffset(lv); // Check and set trainerdata based on ISaveBlock interfaces if (sav is ISaveBlock8Main s8) { Remote.Bot.ReadBytes(ofs, size).CopyTo(s8.MyStatus.Data); } else if (sav is SAV7b slgpe) { Remote.Bot.ReadBytes(ofs, size).CopyTo(slgpe.Blocks.Status.Data); } }
private void SetTrainerData(SaveFile sav, LiveHeXVersion lv) { // Check and set trainerdata based on ISaveBlock interfaces byte[] dest; int startofs = 0; switch (sav) { case ISaveBlock8Main s8: dest = s8.MyStatus.Data; startofs = s8.MyStatus.Offset; break; case ISaveBlock7Main s7: dest = s7.MyStatus.Data; startofs = s7.MyStatus.Offset; break; case ISaveBlock6Main s6: dest = s6.Status.Data; startofs = s6.Status.Offset; break; case SAV7b slgpe: dest = slgpe.Blocks.Status.Data; startofs = slgpe.Blocks.Status.Offset; break; default: dest = Array.Empty <byte>(); break; } if (dest.Length == 0) { return; } var ofs = RamOffsets.GetTrainerBlockOffset(lv); var data = Remote.Bot.com.ReadBytes(ofs, RamOffsets.GetTrainerBlockSize(lv)); data.CopyTo(dest, startofs); }
public void NotifySlotChanged(ISlotInfo slot, SlotTouchType type, PKM pkm) { if (!checkBox2.Checked || !Remote.Bot.Connected) { return; } if (slot is not SlotInfoBox b) { return; } if (!type.IsContentChange()) { return; } int box = b.Box; int slotpkm = b.Slot; Remote.Bot.SendSlot(RamOffsets.WriteBoxData(Remote.Bot.Version) ? pkm.EncryptedBoxData : pkm.EncryptedPartyData, box, slotpkm); }
private void SetTrainerData(SaveFile sav, LiveHeXVersion lv) { // Check and set trainerdata based on ISaveBlock interfaces byte[] dest = sav switch { ISaveBlock8Main s8 => s8.MyStatus.Data, ISaveBlock7Main s7 => s7.MyStatus.Data, ISaveBlock6Core s6 => s6.Status.Data, SAV7b slgpe => slgpe.Blocks.Status.Data, _ => Array.Empty <byte>() }; if (dest.Length == 0) { return; } var ofs = RamOffsets.GetTrainerBlockOffset(lv); var data = Remote.Bot.com.ReadBytes(ofs, dest.Length); data.CopyTo(dest, 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); }
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); } }