Example #1
0
    private void MoveBox(object sender, EventArgs e)
    {
        int index = LB_BoxSelect.SelectedIndex;
        int dir   = sender == B_Up ? -1 : +1;

        editing = renamingBox = true;
        if (!MoveItem(dir))
        {
            System.Media.SystemSounds.Asterisk.Play();
        }
        else if (!SAV.SwapBox(index, index + dir)) // valid but locked
        {
            MoveItem(-dir);                        // undo
            WinFormsUtil.Alert("Locked/Team slots prevent movement of box(es).");
        }
        else
        {
            ChangeBox(sender, EventArgs.Empty);
        }

        editing = renamingBox = false;
    }
Example #2
0
    private void MoveForm(object sender, EventArgs e)
    {
        if (editing)
        {
            return;
        }
        var lb = LB_Form;

        if (lb == null || lb.SelectedIndex < 0)
        {
            WinFormsUtil.Alert("No Form selected.");
            return;
        }

        int index = lb.SelectedIndex;
        int delta = sender == B_FUp ? -1 : 1;

        if (index == 0 && lb.Items.Count == 1)
        {
            return;
        }

        int newIndex = index + delta;

        if (newIndex < 0)
        {
            return;
        }
        if (newIndex >= lb.Items.Count)
        {
            return;
        }

        var item = lb.SelectedItem;

        lb.Items.Remove(item);
        lb.Items.Insert(newIndex, item);
        lb.SelectedIndex = newIndex;
    }
Example #3
0
    private void ToggleForm(object sender, EventArgs e)
    {
        if (editing)
        {
            return;
        }
        var lb = sender == B_FLeft ? LB_NForm : LB_Form;

        if (lb == null || lb.SelectedIndex < 0)
        {
            WinFormsUtil.Alert("No Form selected.");
            return;
        }

        var item = lb.SelectedItem;

        lb.Items.RemoveAt(lb.SelectedIndex);
        var dest = lb == LB_Form ? LB_NForm : LB_Form;

        dest.Items.Add(item);
        dest.SelectedIndex = dest.Items.Count - 1;
    }
        /// <summary>
        /// Function to extract trainerdata values from trainerdata.json
        /// </summary>
        /// <param name="C_SAV">Current Save Editor</param>
        /// <param name="Game">optional Game value in case of mode being game</param>
        /// <returns></returns>
        public string[] parseTrainerJSON(SAVEditor C_SAV, int Game = -1)
        {
            if (!System.IO.File.Exists(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\trainerdata.json"))
            {
                return(parseTrainerData(C_SAV)); // Default trainerdata.txt handling
            }
            string jsonstring = System.IO.File.ReadAllText(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "\\trainerdata.json", System.Text.Encoding.UTF8);

            if (Game == -1)
            {
                Game = C_SAV.SAV.Game;
            }
            if (!checkIfGameExists(jsonstring, Game, out string finaljson))
            {
                return(parseTrainerData(C_SAV, finaljson == "auto"));
            }
            string TID           = getValueFromKey("TID", finaljson);
            string SID           = getValueFromKey("SID", finaljson);
            string OT            = getValueFromKey("OT", finaljson);
            string Gender        = getValueFromKey("Gender", finaljson);
            string Country       = getValueFromKey("Country", finaljson);
            string SubRegion     = getValueFromKey("SubRegion", finaljson);
            string ConsoleRegion = getValueFromKey("3DSRegion", finaljson);

            if (TID.Length == 6 && SID.Length == 4)
            {
                if (new List <int> {
                    33, 32, 31, 30
                }.IndexOf(Game) == -1)
                {
                    WinFormsUtil.Alert("Force Converting G7TID/G7SID to TID/SID");
                }
                int[] tidsid = ConvertTIDSID7toTIDSID(int.Parse(TID), int.Parse(SID));
                TID = tidsid[0].ToString();
                SID = tidsid[1].ToString();
            }
            return(new string[] { TID, SID, OT, Gender, Country, SubRegion, ConsoleRegion });
        }
Example #5
0
        public void EditTypeChart()
        {
            var path = Path.Combine(ROM.PathExeFS, "main");
            var data = FileMitm.ReadAllBytes(path);
            var nso  = new NSO(data);

            byte[] pattern = // N2nn3pia9transport18UnreliableProtocolE
            {
                0x4E, 0x32, 0x6E, 0x6E, 0x33, 0x70, 0x69, 0x61, 0x39, 0x74, 0x72, 0x61, 0x6E, 0x73, 0x70, 0x6F, 0x72,
                0x74, 0x31, 0x38, 0x55, 0x6E, 0x72, 0x65, 0x6C, 0x69, 0x61, 0x62, 0x6C, 0x65, 0x50, 0x72, 0x6F, 0x74,
                0x6F, 0x63, 0x6F, 0x6C, 0x45, 0x00
            };
            int ofs = CodePattern.IndexOfBytes(nso.DecompressedRO, pattern);

            if (ofs < 0)
            {
                WinFormsUtil.Alert("Not able to find type chart data in ExeFS.");
                return;
            }
            ofs += pattern.Length + 0x24; // 0x5B4C0C in lgpe 1.0 RO

            var cdata = new byte[18 * 18];
            var types = ROM.GetStrings(TextName.Types);

            Array.Copy(nso.DecompressedRO, ofs, cdata, 0, cdata.Length);
            var chart = new TypeChartEditor(cdata);

            using var editor = new TypeChart(chart, types);
            editor.ShowDialog();
            if (!editor.Modified)
            {
                return;
            }

            chart.Data.CopyTo(nso.DecompressedRO, ofs);
            data = nso.Write();
            FileMitm.WriteAllBytes(path, data);
        }
        private void AddYouTubeBot(YouTubeSettings config)
        {
            if (YouTube != null)
            {
                return; // already created
            }
            WinFormsUtil.Alert("Please Login with your Browser");
            if (string.IsNullOrWhiteSpace(config.ChannelID))
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(config.ClientID))
            {
                return;
            }
            if (string.IsNullOrWhiteSpace(config.ClientSecret))
            {
                return;
            }

            YouTube = new YouTubeBot(Hub.Config.YouTube, Hub);
            Hub.BotSync.BarrierReleasingActions.Add(() => YouTube.StartingDistribution(config.MessageStart));
        }
Example #7
0
        private void ModifyAllItems(object sender, EventArgs e)
        {
            // Get Current Pouch
            int pouch = CurrentPouch;

            if (pouch < 0)
            {
                return;
            }

            DataGridView dgv = Controls.Find(DGVPrefix + Pouches[pouch].Type, true).FirstOrDefault() as DataGridView;

            for (int i = 0; i < dgv.RowCount; i++)
            {
                string item      = dgv.Rows[i].Cells[0].Value.ToString();
                int    itemindex = Array.IndexOf(itemlist, item);
                if (itemindex > 0)
                {
                    dgv.Rows[i].Cells[1].Value = IsItemCount1((ushort)itemindex, SAV) ? 1 : NUD_Count.Value;
                }
            }
            WinFormsUtil.Alert("Item count modified.");
        }
Example #8
0
    private void B_Delete_Click(object sender, EventArgs e)
    {
        if (LB_DataEntry.SelectedIndex < 1)
        {
            WinFormsUtil.Alert("Cannot delete your first Hall of Fame Clear entry."); return;
        }
        int index = LB_DataEntry.SelectedIndex;

        if (WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Delete Entry {index} from your records?") != DialogResult.Yes)
        {
            return;
        }

        int offset = index * 0x1B4;

        if (index != 15)
        {
            Array.Copy(data, offset + 0x1B4, data, offset, 0x1B4 * (15 - index));
        }
        // Ensure Last Entry is Cleared
        Array.Copy(new byte[0x1B4], 0, data, 0x1B4 * 15, 0x1B4);
        DisplayEntry(LB_DataEntry, EventArgs.Empty);
    }
Example #9
0
        public void EditShinyRate()
        {
            var path = Path.Combine(ROM.PathExeFS, "main");
            var data = FileMitm.ReadAllBytes(path);
            var nso  = new NSO(data);

            var shiny = new ShinyRateGG(nso.DecompressedText);

            if (!shiny.IsEditable)
            {
                WinFormsUtil.Alert("Not able to find shiny rate logic in ExeFS.");
                return;
            }

            using var editor = new ShinyRate(shiny);
            editor.ShowDialog();
            if (!editor.Modified)
            {
                return;
            }

            nso.DecompressedText = shiny.Data;
            FileMitm.WriteAllBytes(path, nso.Write());
        }
        private void ClickSet(object sender, EventArgs e)
        {
            var m = GetSenderInfo(ref sender, out SlotChange info);

            if (m == null)
            {
                return;
            }

            var editor = m.SE.PKME_Tabs;
            var sav    = m.SE.SAV;

            if (info.IsParty && editor.IsEmptyOrEgg && sav.IsPartyAllEggs(info.Slot) && !m.SE.HaX)
            {
                WinFormsUtil.Alert(MsgSaveSlotEmpty); return;
            }
            if (m.SE.SAV.IsSlotLocked(info.Box, info.Slot))
            {
                WinFormsUtil.Alert(MsgSaveSlotLocked); return;
            }

            if (!editor.EditsComplete)
            {
                return;
            }

            PKM pk = editor.PreparePKM();

            var errata = sav.IsPKMCompatible(pk);

            if (errata.Count > 0 && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, string.Join(Environment.NewLine, errata), MsgContinue))
            {
                return;
            }

            m.HoverCancel();

            if (info.Type == StorageSlotType.Party) // Party
            {
                // If info.Slot isn't overwriting existing PKM, make it write to the lowest empty PKM info.Slot
                if (sav.PartyCount < info.Slot + 1)
                {
                    var pb   = (PictureBox)WinFormsUtil.GetUnderlyingControl(sender);
                    var view = WinFormsUtil.FindFirstControlOfType <ISlotViewer <PictureBox> >(pb);
                    info = view.GetSlotData(view.SlotPictureBoxes[sav.PartyCount]);
                }
                m.SetPKM(pk, info, true, Resources.slotSet);
            }
            else if (info.Type == StorageSlotType.Box || m.SE.HaX)
            {
                if (info.Type == StorageSlotType.Box)
                {
                    m.SE.UndoStack.Push(new SlotChange(info, sav));
                    m.SE.Menu_Undo.Enabled = true;
                }

                m.SetPKM(pk, info, true, Resources.slotSet);
            }
            else
            {
                return;
            }

            editor.LastData = pk.Data;
            m.SE.RedoStack.Clear(); m.SE.Menu_Redo.Enabled = false;
        }
Example #11
0
 private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
 {
     WinFormsUtil.Alert(e.Exception.Message);
 }
Example #12
0
 private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
 {
     WinFormsUtil.Alert(e.ExceptionObject.ToString());
 }
        // Command to set in box (for multiple imports)
        public void ClickSet(object sender, int slot)
        {
            SlotChangeManager m = GetSenderInfo(ref sender, out SlotChange info, slot);

            if (m == null)
            {
                return;
            }

            var editor = m.SE.PKME_Tabs;
            var sav    = m.SE.SAV;

            if (info.IsParty && editor.IsEmptyOrEgg && sav.IsPartyAllEggs(info.Slot - 30) && !m.SE.HaX)
            {
                WinFormsUtil.Alert("Can't have empty/egg party."); return;
            }
            if (m.SE.SAV.IsSlotLocked(info.Box, info.Slot))
            {
                WinFormsUtil.Alert("Can't set to locked slot."); return;
            }

            PKM pk = editor.PreparePKM();

            string[] errata = sav.IsPKMCompatible(pk);
            if (errata.Length > 0 && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, string.Join(Environment.NewLine, errata), "Continue?"))
            {
                return;
            }

            if (info.Slot >= 30)
            {
                info.Box = -1;
            }
            if (info.Slot >= 30 && info.Slot < 36) // Party
            {
                // If info.Slot isn't overwriting existing PKM, make it write to the lowest empty PKM info.Slot
                if (sav.PartyCount < info.Slot + 1 - 30)
                {
                    info.Slot   = sav.PartyCount + 30;
                    info.Offset = m.SE.GetPKMOffset(info.Slot);
                }
                m.SetPKM(pk, info, true, Resources.slotSet);
            }
            else if (info.Slot < 30 || m.SE.HaX)
            {
                if (info.Slot < 30)
                {
                    m.SE.UndoStack.Push(new SlotChange
                    {
                        Box    = info.Box,
                        Slot   = info.Slot,
                        Offset = info.Offset,
                        PKM    = sav.GetStoredSlot(info.Offset)
                    });
                    m.SE.Menu_Undo.Enabled = true;
                }

                m.SetPKM(pk, info, true, Resources.slotSet);
            }

            editor.LastData = pk.Data;
            m.SE.RedoStack.Clear(); m.SE.Menu_Redo.Enabled = false;
        }
Example #14
0
    private void B_GetTickets_Click(object sender, EventArgs e)
    {
        var Pouches  = SAV.Inventory;
        var itemlist = GameInfo.Strings.GetItemStrings(SAV.Generation, SAV.Version).ToArray();

        for (int i = 0; i < itemlist.Length; i++)
        {
            if (string.IsNullOrEmpty(itemlist[i]))
            {
                itemlist[i] = $"(Item #{i:000})";
            }
        }

        const int oldsea = 0x178;

        int[] tickets = { 0x109, 0x113, 0x172, 0x173, oldsea }; // item IDs
        if (!SAV.Japanese && DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, $"Non Japanese save file. Add {itemlist[oldsea]} (unreleased)?"))
        {
            tickets = tickets.Take(tickets.Length - 1).ToArray(); // remove old sea map
        }
        var p = Pouches.FirstOrDefault(z => z.Type == InventoryType.KeyItems);

        if (p == null)
        {
            throw new ArgumentException(nameof(InventoryType));
        }

        // check for missing tickets
        var missing = tickets.Where(z => !p.Items.Any(item => item.Index == z && item.Count == 1)).ToList();
        var have    = tickets.Except(missing).ToList();

        if (missing.Count == 0)
        {
            WinFormsUtil.Alert("Already have all tickets.");
            B_GetTickets.Enabled = false;
            return;
        }

        // check for space
        int end = Array.FindIndex(p.Items, z => z.Index == 0);

        if (end + missing.Count >= p.Items.Length)
        {
            WinFormsUtil.Alert("Not enough space in pouch.", "Please use the InventoryEditor.");
            B_GetTickets.Enabled = false;
            return;
        }

        var added  = string.Join(", ", missing.Select(u => itemlist[u]));
        var addmsg = $"Add the following items?{Environment.NewLine}{added}";

        if (have.Count > 0)
        {
            string had     = string.Join(", ", have.Select(u => itemlist[u]));
            var    havemsg = $"Already have:{Environment.NewLine}{had}";
            addmsg += Environment.NewLine + Environment.NewLine + havemsg;
        }
        if (DialogResult.Yes != WinFormsUtil.Prompt(MessageBoxButtons.YesNo, addmsg))
        {
            return;
        }

        // insert items at the end
        for (int i = 0; i < missing.Count; i++)
        {
            var item = p.Items[end + i];
            item.Index = missing[i];
            item.Count = 1;
        }

        string alert = $"Inserted the following items to the Key Items Pouch:{Environment.NewLine}{added}";

        WinFormsUtil.Alert(alert);
        SAV.Inventory = Pouches;

        B_GetTickets.Enabled = false;
    }
        public void randomizeLevelUpMoves(Random rnd)
        {
            // ORAS: 10682 moves learned on levelup/birth.
            // 5593 are STAB. 52.3% are STAB.
            // Steelix learns the most @ 25 (so many level 1)!
            // Move relearner ingame glitch fixed (52 tested), but keep below 75:
            // https://twitter.com/Drayano60/status/807297858244411397

            int[] firstMoves = { 1, 40, 52, 55, 64, 71, 84, 98, 122, 141 };
            // Pound, Poison Sting, Ember, Water Gun, Peck, Absorb, Thunder Shock, Quick Attack, Lick, Leech Life

            int[] banned = new[] { 165, 621, 464 }.Concat(Legal.Z_Moves).ToArray(); // Struggle, Hyperspace Fury, Dark Void

            // Move Stats
            Move[] moveTypes = Main.Config.Moves;

            // Set up Randomized Moves
            int[] randomMoves = Enumerable.Range(1, movelist.Length - 1).Select(i => i).ToArray();
            Util.Shuffle(randomMoves);
            int ctr = 0;

            for (int i = 0; i < CB_Species.Items.Count; i++)
            {
                CB_Species.SelectedIndex = i; // Get new Species
                int count   = getPkmnLevelUpMovesCount() - 1;
                int species = WinFormsUtil.getIndex(CB_Species);

                // Default First Move
                dgv.Rows[0].Cells[0].Value = 1;
                dgv.Rows[0].Cells[1].Value = movelist[firstMoves[rnd.Next(0, firstMoves.Length)]];
                for (int j = 1; j < dgv.Rows.Count - 1; j++)
                {
                    int move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr);

                    while (banned.Contains(move)) /* Invalid */
                    {
                        move = Randomizer.getRandomSpecies(ref randomMoves, ref ctr);
                    }

                    // Assign Move
                    dgv.Rows[j].Cells[1].Value = movelist[move];
                    // Assign Level
                    if (j >= count)
                    {
                        string level = (dgv.Rows[count - 1].Cells[0].Value ?? 0).ToString();
                        ushort lv;
                        UInt16.TryParse(level, out lv);
                        if (lv > 100)
                        {
                            lv = 100;
                        }
                        dgv.Rows[j].Cells[0].Value = lv + (j - count) + 1;
                    }
                    if (CHK_Spread.Checked)
                    {
                        dgv.Rows[j].Cells[0].Value = ((int)(j * (NUD_Level.Value / (dgv.Rows.Count - 1)))).ToString();
                    }
                }
            }
            CB_Species.SelectedIndex = 0;
            WinFormsUtil.Alert("All Pokemon's Level Up Moves have been randomized!");
        }
Example #16
0
        private void SyncGameArchiveMenuItem_Click(object sender, EventArgs e)
        {
            var syncResult = this.gasBiz.SyncGameArchiveList(GlobalConfig.GameArchiveListUrl);

            WinFormsUtil.Alert("同步成功!");
        }