Exemple #1
0
        private void B_RandAll_Click(object sender, EventArgs e)
        {
            DialogResult ync = Util.Prompt(MessageBoxButtons.YesNoCancel,
                                           "Randomize by BST: Yes" + Environment.NewLine +
                                           "Randomize Randomly: No" + Environment.NewLine +
                                           "Abort: Cancel");

            if (ync != DialogResult.Yes && ync != DialogResult.No)
            {
                return;
            }
            if (ync == DialogResult.No)
            {
                for (int i = 0; i < LB_Encounters.Items.Count; i++)
                {
                    LB_Encounters.SelectedIndex = i;
                    int species = Util.rand.Next(1, 721);
                    CB_Species.SelectedIndex = species;
                }
                return;
            }

            // Randomize by BST
            int[] sL  = Randomizer.getSpeciesList(G1: true, G2: true, G3: true, G4: true, G5: true, G6: true, L: false, E: false, Shedinja: false);
            int   ctr = 0;

            for (int i = 0; i < LB_Encounters.Items.Count; i++)
            {
                LB_Encounters.SelectedIndex = i;
                int species = CB_Species.SelectedIndex;

                int bst   = Main.SpeciesStat[species].BST;
                int tries = 0;
                var pkm   = Main.SpeciesStat[species = Randomizer.getRandomSpecies(ref sL, ref ctr)];
                while (!((pkm.BST * (5 - ++tries / 722) / 6 < bst) && pkm.BST * (6 + ++tries / 722) / 5 > bst))
                {
                    pkm = Main.SpeciesStat[species = Randomizer.getRandomSpecies(ref sL, ref ctr)];
                }

                CB_Species.SelectedIndex = species;
            }
        }
Exemple #2
0
        // IO
        private void B_Export_Click(object sender, EventArgs e)
        {
            if (files.Length <= 0)
            {
                return;
            }
            SaveFileDialog Dump = new SaveFileDialog {
                Filter = "Text File|*.txt"
            };
            DialogResult sdr = Dump.ShowDialog();

            if (sdr != DialogResult.OK)
            {
                return;
            }
            bool   newline = Util.Prompt(MessageBoxButtons.YesNo, "Remove newline formatting codes? (\\n,\\r,\\c)", "Removing newline formatting will make it more readable but will prevent any importing of that dump.") == DialogResult.Yes;
            string path    = Dump.FileName;

            exportTextFile(path, newline);
        }
Exemple #3
0
        private void B_RemoveLine_Click(object sender, EventArgs e)
        {
            int currentRow = dgv.CurrentRow.Index;

            if (currentRow < dgv.Rows.Count - 1)
            {
                if (ModifierKeys != Keys.Control && DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo,
                                                                                    "Deleting a row above other lines will shift all subsequent lines.", "Continue?"))
                {
                    return;
                }
            }
            dgv.Rows.RemoveAt(currentRow);

            // Resequence the Index Value column
            for (int i = 0; i < dgv.Rows.Count; i++)
            {
                dgv.Rows[i].Cells[0].Value = i.ToString();
            }
        }
Exemple #4
0
        private void B_Dump_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Dump all Personal Entries to Text File?"))
            {
                return;
            }

            dumping = true;
            string result = "";

            for (int i = 0; i < CB_Species.Items.Count; i++)
            {
                CB_Species.SelectedIndex = i; // Get new Species
                result += "======" + Environment.NewLine + entry + " " + CB_Species.Text + Environment.NewLine + "======" + Environment.NewLine;

                result += String.Format("Base Stats: {0}.{1}.{2}.{3}.{4}.{5} (BST: {6})", TB_BaseHP.Text, TB_BaseATK.Text, TB_BaseDEF.Text, TB_BaseSPA.Text, TB_BaseSPD.Text, TB_BaseSPE.Text, bst) + Environment.NewLine;
                result += String.Format("EV Yield: {0}.{1}.{2}.{3}.{4}.{5}", TB_HPEVs.Text, TB_ATKEVs.Text, TB_DEFEVs.Text, TB_SPAEVs.Text, TB_SPDEVs.Text, TB_SPEEVs.Text) + Environment.NewLine;
                result += String.Format("Abilities: {0} (1) | {1} (2) | {2} (H)", CB_Ability1.Text, CB_Ability2.Text, CB_Ability3.Text) + Environment.NewLine;

                result += String.Format(((CB_Type1.SelectedIndex != CB_Type2.SelectedIndex) ? "Type: {0} / {1}" : "Type: {0}"), CB_Type1.Text, CB_Type2.Text);

                result += String.Format("Item 1 (50%): {0}", CB_HeldItem1.Text) + Environment.NewLine;
                result += String.Format("Item 2 (5%): {0}", CB_HeldItem2.Text) + Environment.NewLine;
                result += String.Format("Item 3 (1%): {0}", CB_HeldItem3.Text) + Environment.NewLine;
                // I don't want to add anything else. Should be pretty easy for anyone else to expand.

                result += Environment.NewLine;
            }
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.FileName = "Personal Entries.txt";
            sfd.Filter   = "Text File|*.txt";

            System.Media.SystemSounds.Asterisk.Play();
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                string path = sfd.FileName;
                File.WriteAllText(path, result, System.Text.Encoding.Unicode);
            }
            dumping = false;
        }
Exemple #5
0
        private void B_Dump_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Dump all Evolutions to Text File?"))
            {
                return;
            }

            dumping = true;
            string result = "";

            for (int i = 0; i < CB_Species.Items.Count; i++)
            {
                CB_Species.SelectedIndex = i; // Get new Species
                result += "======" + Environment.NewLine + entry + " " + CB_Species.Text + Environment.NewLine + "======" + Environment.NewLine;
                for (int j = 0; j < 8; j++)
                {
                    int methodval = mb[j].SelectedIndex;
                    int param     = pb[j].SelectedIndex;
                    int poke      = rb[j].SelectedIndex;
                    if (poke > 0 && methodval > 0)
                    {
                        result += mb[j].Text + ((pb[j].Visible) ? " [" + pb[j].Text + "]" : "") + " into " + rb[j].Text + Environment.NewLine;
                    }
                }

                result += Environment.NewLine;
            }
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.FileName = "Evolutions.txt";
            sfd.Filter   = "Text File|*.txt";

            System.Media.SystemSounds.Asterisk.Play();
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                string path = sfd.FileName;
                File.WriteAllText(path, result, System.Text.Encoding.Unicode);
            }
            dumping = false;
        }
Exemple #6
0
        private void B_RandAll_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Randomize all resulting species?", "Evolution methods and parameters will stay the same."))
            {
                return;
            }
            Random rnd = new Random();

            for (int i = 0; i < CB_Species.Items.Count; i++)
            {
                CB_Species.SelectedIndex = i; // Get new Species
                for (int j = 0; j < mb.Length; j++)
                {
                    if (mb[j].SelectedIndex > 0)
                    {
                        rb[i].SelectedIndex = rnd.Next(1, 722);
                    }
                }
            }
            setList();
            Util.Alert("All Pokemon's Evolutions have been randomized!");
        }
Exemple #7
0
        private void B_Maison_Click(object sender, EventArgs e)
        {
            if (threads > 0)
            {
                Util.Alert("Please wait for all operations to finish first."); return;
            }
            DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Edit Super Maison instead of Normal Maison?", "Yes = Super, No = Normal, Cancel = Abort");

            if (dr == DialogResult.Cancel)
            {
                return;
            }

            new Thread(() =>
            {
                bool super     = (dr == DialogResult.Yes);
                string[] files = { (super) ? "maisontrS" : "maisontrN", (super) ? "maisonpkS" : "maisonpkN" };
                fileGet(files);
                Invoke((Action)(() => new Maison(super).ShowDialog()));
                fileSet(files);
            }).Start();
        }
Exemple #8
0
        private bool checkIfExeFS(string path)
        {
            string[] files = Directory.GetFiles(path);
            if (files.Length != 3)
            {
                return(false);
            }

            FileInfo fi = new FileInfo(files[0]);

            if (fi.Name.Contains("code"))
            {
                if (fi.Length % 0x200 != 0 && (Util.Prompt(MessageBoxButtons.YesNo, "Detected Compressed code.bin.", "Decompress? File will be replaced.") == DialogResult.Yes))
                {
                    new Thread(() => { threads++; new BLZCoder(new[] { "-d", files[0] }, pBar1); threads--; Util.Alert("Decompressed!"); }).Start();
                }

                ExeFS = path;
                return(true);
            }
            return(false);
        }
Exemple #9
0
        private void B_DumpMaps_Click(object sender, EventArgs e)
        {
            if (Util.Prompt(MessageBoxButtons.YesNoCancel, "Export all MapImages?") != DialogResult.Yes)
            {
                return;
            }

            debugToolDumping = true;
            const string folder = "MapImages";

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            string[] result = new string[CB_LocationID.Items.Count];
            for (int i = 0; i < CB_LocationID.Items.Count; i++)
            {
                mapView.DrawMap = i;
                Image img = mapView.getMapImage(crop: true);
                using (MemoryStream ms = new MemoryStream())
                {
                    //error will throw from here
                    img.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    byte[] data = ms.ToArray();
                    File.WriteAllBytes(Path.Combine(folder, $"{zdLocations[i].Replace('?', '-')} ({i}).png"), data);
                }
                string l = mm.EntryList.Where(t => t != 0xFFFF).Aggregate("", (current, t) => current + t.ToString("000" + " "));
                result[i] = $"{i.ToString("000")}\t{CB_LocationID.Items[i]}\t{l}";
            }
            if (Util.Prompt(MessageBoxButtons.YesNoCancel, "Write Map parse output?") == DialogResult.Yes)
            {
                File.WriteAllLines("MapLocations.txt", result);
            }
            CB_LocationID.SelectedIndex = 0;
            Util.Alert("All Map images have been dumped to " + folder + ".");
            debugToolDumping = false;
        }
Exemple #10
0
 // ExeFS Subform Items
 private void rebuildExeFS(object sender, EventArgs e)
 {
     if (ExeFS != null)
         if (Util.Prompt(MessageBoxButtons.YesNo, "Rebuild ExeFS?") == DialogResult.Yes)
         {
             string[] files = Directory.GetFiles(ExeFS);
             int file = 0; if (files[1].Contains("code")) file = 1;
             SaveFileDialog sfd = new SaveFileDialog();
             sfd.FileName = "exefs.bin";
             sfd.Filter = "Binary File|*.*";
             if (sfd.ShowDialog() == DialogResult.OK)
             {
                 new Thread(() =>
                 {
                     threads++;
                     new blz.BLZCoder(new string[] { "-en", files[file] }, pBar1);
                     Util.Alert("Compressed!");
                     ExeFSTool.set(Directory.GetFiles(ExeFS), sfd.FileName);
                     threads--;
                 }).Start();
             }
         }
 }
Exemple #11
0
        private void openQuick(string path)
        {
            FileInfo fi = new FileInfo(path);

            if (!Directory.Exists(path))
            {
                return;
            }

            if (threads > 0)
            {
                Util.Alert("Please wait for all operations to finish first."); return;
            }
            if (fi.Name.Contains("code.bin"))
            {
                if (fi.Length % 0x200 == 0 && (Util.Prompt(MessageBoxButtons.YesNo, "Detected Decompressed code.bin.", "Compress? File will be replaced.") == DialogResult.Yes))
                {
                    new Thread(() => { threads++; new BLZCoder(new[] { "-en", path }, pBar1); threads--; Util.Alert("Compressed!"); }).Start();
                }
                else if (Util.Prompt(MessageBoxButtons.YesNo, "Detected Compressed code.bin.", "Decompress? File will be replaced.") == DialogResult.Yes)
                {
                    new Thread(() => { threads++; new BLZCoder(new[] { "-d", path }, pBar1); threads--; Util.Alert("Decompressed!"); }).Start();
                }
            }
            else
            {
                // Check for ROMFS/EXEFS
                RomFS = ExeFS = null; // Reset
                string[] folders = Directory.GetDirectories(path);
                int      count   = folders.Length;
                if (count != 2 && count != 1)
                {
                    return;                           // Only want exefs & romfs (can have exheader there too, it's not a folder)
                }
                {
                    // First file should be 'exe'
                    if (new FileInfo(folders[0]).Name.ToLower().Contains("exe") && Directory.Exists(folders[0]))
                    {
                        checkIfExeFS(folders[0]);
                    }
                    if (new FileInfo(folders[count - 1]).Name.ToLower().Contains("rom") && Directory.Exists(folders[count - 1]))
                    {
                        checkIfRomFS(folders[count - 1]);
                    }

                    GB_RomFS.Enabled    = (RomFS != null);
                    GB_ExeFS.Enabled    = (RomFS != null && ExeFS != null);
                    B_MoveTutor.Enabled = oras; // Default false unless loaded
                    if (RomFS != null)
                    {
                        if (L_Game.Text == "Game Loaded: ORAS" || L_Game.Text == "Game Loaded: XY")
                        {
                            Directory.Delete("personal", true);
                        }                                       // Force reloading of personal data if the game is switched.
                        L_Game.Text = (oras) ? "Game Loaded: ORAS" : "Game Loaded: XY"; TB_Path.Text = path;
                    }
                    else if (ExeFS != null)
                    {
                        L_Game.Text = "ExeFS loaded - no RomFS"; TB_Path.Text = path;
                    }
                    else
                    {
                        L_Game.Text = "No Game Loaded"; TB_Path.Text = "";
                    }

                    if (RomFS != null)
                    {
                        // Trigger Data Loading
                        if (RTB_Status.Text.Length > 0)
                        {
                            RTB_Status.Clear();
                        }
                        updateStatus("Data found! Loading persistent data for subforms...", false);
                        changeLanguage(null, null);
                    }

                    // Method finished.
                    SystemSounds.Asterisk.Play();
                }
            }
        }
Exemple #12
0
 private void L_Game_Click(object sender, EventArgs e)
 {
     if (GB_RomFS.Enabled && RomFS != null && ModifierKeys == Keys.Control)
         if (DialogResult.Yes == Util.Prompt(MessageBoxButtons.YesNo, "Restore Original Files?"))
             restoreGARCs(oras, allGARCs);
 }
Exemple #13
0
        // Randomization
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            if (Util.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings @ Horde Tab.") != DialogResult.Yes)
            {
                return;
            }

            Enabled = false;

            // Calculate % diff we will apply to each level
            decimal leveldiff = (100 + NUD_LevelAmp.Value) / 100;

            // Nonrepeating List Start
            int[] sL = Randomizer.getSpeciesList(CHK_G1.Checked, CHK_G2.Checked, CHK_G3.Checked,
                                                 CHK_G4.Checked, CHK_G5.Checked, CHK_G6.Checked, CHK_L.Checked, CHK_E.Checked);

            int ctr = 0;

            int[] slotArray = Enumerable.Range(0, max.Length).Select(a => a).ToArray();

            for (int i = 0; i < CB_LocationID.Items.Count; i++) // for every location
            {
                CB_LocationID.SelectedIndex = i;
                if (!hasData())
                {
                    continue;             // Don't randomize if doesn't have data.
                }
                // Assign Levels
                if (CHK_Level.Checked)
                {
                    for (int l = 0; l < max.Length; l++)
                    {
                        min[l].Value = max[l].Value = (max[l].Value <= 1) ? max[l].Value : Math.Max(1, Math.Min(100, (int)((leveldiff) * max[l].Value)));
                    }
                }

                // Get a new list of Pokemon so that DexNav does not crash.
                int[] list = new int[max.Length];
                int   used = 19;

                // Count up how many slots are active.
                for (int s = 0; s < max.Length; s++)
                {
                    if (spec[s].SelectedIndex > 0)
                    {
                        list[s] = spec[s].SelectedIndex;
                    }
                }

                // At most 18, but don't chew if there's only a few slots.
                int   cons       = list.Count(a => a != 0);
                int[] RandomList = new int[(cons > 18) ? (18 - (cons / 8)) : cons];

                // Fill Location List
                if (!CHK_BST.Checked)
                {
                    for (int z = 0; z < RandomList.Length; z++)
                    {
                        RandomList[z] = Randomizer.getRandomSpecies(ref sL, ref ctr);
                    }
                }
                else
                {
                    int oldBST = 0;
                    for (int s = 0; s < max.Length; s++)
                    {
                        if (spec[s].SelectedIndex > 0)
                        {
                            oldBST = personal[spec[s + 2].SelectedIndex].Take(6).Sum(b => (ushort)b); break;
                        }
                    }

                    for (int z = 0; z < RandomList.Length; z++)
                    {
                        int species = Randomizer.getRandomSpecies(ref sL, ref ctr);
                        int newBST  = personal[species].Take(6).Sum(b => (ushort)b);
                        while (!(newBST * 4 / 5 < oldBST && newBST * 6 / 5 > oldBST))
                        {
                            species = sL[rand.Next(1, sL.Length)]; newBST = personal[species].Take(6).Sum(b => (ushort)b);
                        }
                        RandomList[z] = species;
                    }
                }

                // Assign Slots
                while (used < RandomList.Distinct().Count() || used > 18) // Can just arbitrarily assign slots.
                {
                    int ctrSingle = 0;
                    Util.Shuffle(slotArray);
                    for (int s = 0; s < max.Length; s++)
                    {
                        int slot = slotArray[s];
                        if (spec[slot].SelectedIndex != 0) // If the slot is in use
                        {
                            list[slot] = Randomizer.getRandomSpecies(ref RandomList, ref ctrSingle);
                        }
                    }
                    used = countUnique(list);
                    if (used != RandomList.Length)
                    {
                        ShuffleSlots(ref list, RandomList.Length);
                    }
                    used = countUnique(list);
                }

                // Fill Slots
                for (int slot = 0; slot < max.Length; slot++)
                {
                    if (spec[slot].SelectedIndex != 0)
                    {
                        spec[slot].SelectedIndex = list[slot];
                        setRandomForm(slot, spec[slot].SelectedIndex);
                    }
                }

                B_Save_Click(sender, e);
            }
            Enabled = true;
            Util.Alert("Randomized!");
        }
Exemple #14
0
        private static int[] sL; // Random Species List
        private void B_RandAll_Click(object sender, EventArgs e)
        {
            if (DialogResult.Yes != Util.Prompt(MessageBoxButtons.YesNo, "Randomize all resulting species?", "Evolution methods and parameters will stay the same."))
            {
                return;
            }

            // Set up advanced randomization options
            bool rBST  = CHK_BST.Checked;
            bool rEXP  = CHK_Exp.Checked;
            bool rType = CHK_Type.Checked;
            int  ctr   = 0;

            sL = Randomizer.RandomSpeciesList;

            for (int i = 0; i < CB_Species.Items.Count; i++)
            {
                CB_Species.SelectedIndex = i;
                for (int j = 0; j < mb.Length; j++)
                {
                    if (mb[j].SelectedIndex > 0)
                    {
                        // Get a new random species
                        int          oldSpecies     = rb[j].SelectedIndex;
                        PersonalInfo oldpkm         = Main.SpeciesStat[oldSpecies];
                        int          currentSpecies = Array.IndexOf(specieslist, CB_Species.Text);
                        int          loopctr        = 0; // altering calculatiosn to prevent infinite loops
defspecies:
                        int newSpecies = Randomizer.getRandomSpecies(ref sL, ref ctr);
                        PersonalInfo pkm = Main.SpeciesStat[newSpecies];
                        loopctr++;

                        // Verify it meets specifications
                        if (newSpecies == currentSpecies && loopctr < Main.Config.MaxSpeciesID * 10) // no A->A evolutions
                        {
                            goto defspecies;
                        }
                        if (rEXP) // Experience Growth Rate matches
                        {
                            if (oldpkm.EXPGrowth != pkm.EXPGrowth)
                            {
                                goto defspecies;
                            }
                        }
                        if (rType) // Type has to be somewhat similar
                        {
                            if (!oldpkm.Types.Contains(pkm.Types[0]) || !oldpkm.Types.Contains(pkm.Types[1]))
                            {
                                goto defspecies;
                            }
                        }
                        if (rBST)            // Base stat total has to be close
                        {
                            const int l = 5; // tweakable scalars
                            const int h = 6;
                            if (!(pkm.BST * l / (h + loopctr / Main.Config.MaxSpeciesID) < oldpkm.BST && (pkm.BST * h + loopctr / Main.Config.MaxSpeciesID) / l > oldpkm.BST))
                            {
                                goto defspecies;
                            }
                        }
                        // assign random val
                        rb[j].SelectedIndex = newSpecies;
                    }
                }
            }
            setList();
            Util.Alert("All Pokemon's Evolutions have been randomized!");
        }
Exemple #15
0
        internal static void encryptVar(BinaryWriter bw, string line, ref int i, ref ushort key)
        {
            ushort val = line[i];

            if (val == '\\')        // Line Break
            {
                if (line[i + 1] == 'n')
                {
                    i++;
                    bw.Write(encryptU16('\n', ref key));
                }
                else if (line[i + 1] == 'r')
                {
                    bw.Write(encryptU16(0x10, ref key)); i++;
                    bw.Write(encryptU16(1, ref key));
                    bw.Write(encryptU16(0xBE00, ref key));
                }
                else if (line[i + 1] == 'c')
                {
                    bw.Write(encryptU16(0x10, ref key)); i++;
                    bw.Write(encryptU16(1, ref key));
                    bw.Write(encryptU16(0xBE01, ref key));
                }
                else if (line[i + 1] == '\\') // Not Formatting
                {
                    i++;
                    bw.Write(encryptU16('\\', ref key));
                }
                else if (line[i + 1] == '[') // Not Variable
                {
                    i++;
                    bw.Write(encryptU16('[', ref key));
                }
                else
                {
                    if (DialogResult.Yes != Util.Prompt(
                            MessageBoxButtons.YesNo,
                            "Encoding Error - Please Resolve:",
                            string.Format("File: {3}{0}Char: {1}{0}Line:{0}{2}", Environment.NewLine, line[i + 1], line, i),
                            "Treat as literal '\\'?"))
                    {
                        throw new Exception("Invalid terminated line: " + line);
                    }

                    i++;
                    bw.Write(encryptU16('\\', ref key));
                }
            }
            else if (val == '[')    // Special Variable
            {
                int bracket = line.Substring(i + 1).IndexOf(']');
                if (bracket < 3)
                {
                    throw new Exception("Variable encoding error!");
                }

                // [VAR X(a, b)]
                // Remove the [ ] -> VAR X(a, b)
                string varCMD = line.Substring(i + 1, bracket);
                i += bracket + 1; // Advance the index to the end of the bracket.

                string[] split     = varCMD.Split(' ');
                string   varMethod = split[0];                                                       // Returns VAR or WAIT or ~
                string   varType   = split.Length > 1 ? varCMD.Substring(varMethod.Length + 1) : ""; // Returns the remainder of the var command data.
                ushort   varValue;

                // Set up argument storage (even if it not used)
                List <ushort> args = new List <ushort>();

                try
                {
                    switch (varMethod)
                    {
                    case "~":           // Blank Text Line Variable (No text set - debug/quality testing variable?)
                    {
                        varValue = 0xBDFF;
                        args.Add(Convert.ToUInt16(varType));
                        break;
                    }

                    case "WAIT":        // Event pause Variable.
                    {
                        varValue = 0xBE02;
                        args.Add(Convert.ToUInt16(varType));
                        break;
                    }

                    case "VAR":         // Text Variable
                    {
                        varValue = getVariableBytes(varType, ref args, varCMD.IndexOf('(') < 0);
                        break;
                    }

                    default: throw new Exception("Unknown variable method type!");
                    }
                }
                catch (Exception e)
                {
                    Util.Alert("Variable error. Current line text is:", line, e.ToString());
                    throw new Exception("Cannot save the file.");
                }

                // Write the Variable prefix.
                bw.Write(encryptU16(0x0010, ref key));
                // Write Length of the following Variable Data
                bw.Write(encryptU16((ushort)(1 + args.Count), ref key));
                // Write the Variable type.
                bw.Write(encryptU16(varValue, ref key));

                foreach (ushort t in args)
                {
                    bw.Write(encryptU16(t, ref key));
                }

                // Done.
            }
        }
Exemple #16
0
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            Util.Alert("Randomization currently disabled"); return;

            if (Util.Prompt(MessageBoxButtons.YesNo, "Randomize all?", "Cannot undo.") == DialogResult.Yes)
            {
                bool smart = Util.Prompt(MessageBoxButtons.YesNo, "Smart Randomize by Base Stat Total?", "Pokemon strength variance will attempt to match ingame.") == DialogResult.Yes;
                this.Enabled = false;

                // Nonrepeating List Start
                int[] sL        = Randomizer.RandomSpeciesList;
                int   ctr       = 0;
                int[] slotArray = Enumerable.Range(0, max.Length).Select(a => (int)a).ToArray();

                for (int i = 0; i < CB_LocationID.Items.Count; i++) // for every location
                {
                    CB_LocationID.SelectedIndex = i;
                    if (!hasData())
                    {
                        continue;             // Don't randomize if doesn't have data.
                    }
                    // Get a new list of Pokemon so that DexNav does not crash.
                    int[] list = new int[max.Length];
                    int   used = 19;

                    // Count up how many slots are active.
                    for (int s = 0; s < max.Length; s++)
                    {
                        if (spec[s].SelectedIndex > 0)
                        {
                            list[s] = spec[s].SelectedIndex;
                        }
                    }

                    // At most 18, but don't chew if there's only a few slots.
                    int   cons       = list.Count(a => a != 0);
                    int[] RandomList = new int[(cons > 18) ? (18 - (cons / 8)) : cons];

                    // Fill Location List
                    if (!smart)
                    {
                        for (int z = 0; z < RandomList.Length; z++)
                        {
                            RandomList[z] = Randomizer.getRandomSpecies(ref sL, ref ctr);
                        }
                    }
                    else
                    {
                        int oldBST = 0;
                        for (int s = 0; s < max.Length; s++)
                        {
                            if (spec[s].SelectedIndex > 0)
                            {
                                oldBST = personal[spec[s + 2].SelectedIndex].Take(6).Sum(b => (ushort)b); break;
                            }
                        }

                        for (int z = 0; z < RandomList.Length; z++)
                        {
                            int species = Randomizer.getRandomSpecies(ref sL, ref ctr);
                            int newBST  = personal[species].Take(6).Sum(b => (ushort)b);
                            while (!(newBST * 4 / 5 < oldBST && newBST * 6 / 5 > oldBST))
                            {
                                species = rand.Next(1, 722); newBST = personal[species].Take(6).Sum(b => (ushort)b);
                            }
                            RandomList[z] = species;
                        }
                    }

                    // Assign Slots
                    while (used < RandomList.Length || used > 18) // Can just arbitrarily assign slots.
                    {
                        int ctrSingle = 0;
                        Util.Shuffle(slotArray);
                        for (int s = 0; s < max.Length; s++)
                        {
                            int slot = slotArray[s];
                            if (spec[slot].SelectedIndex != 0) // If the slot is in use
                            {
                                list[slot] = Randomizer.getRandomSpecies(ref RandomList, ref ctrSingle);
                            }
                        }
                        ShuffleSlots(ref list, RandomList.Length);
                        used = countUnique(list);
                    }

                    // Fill Slots
                    for (int slot = 0; slot < max.Length; slot++)
                    {
                        if (spec[slot].SelectedIndex != 0)
                        {
                            spec[slot].SelectedIndex = list[slot];
                            setRandomForm(slot, spec[slot].SelectedIndex);
                        }
                    }

                    B_Save_Click(sender, e);
                }
                this.Enabled = true;
                Util.Alert("Randomized!");
            }
        }
Exemple #17
0
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            if (Util.Prompt(MessageBoxButtons.YesNo, "Randomize all?", "Cannot undo.") == DialogResult.Yes)
            {
                bool smart = Util.Prompt(MessageBoxButtons.YesNo, "Smart Randomize by Base Stat Total?", "Pokemon strength variance will attempt to match ingame.") == DialogResult.Yes;
                this.Enabled = false;

                // Nonrepeating List Start
                int[] sL  = Randomizer.RandomSpeciesList;
                int   ctr = 0;

                for (int i = 0; i < CB_LocationID.Items.Count; i++) // for every location
                {
                    CB_LocationID.SelectedIndex = i;
                    if (!hasData())
                    {
                        continue;             // Don't randomize if doesn't have data.
                    }
                    for (int slot = 0; slot < max.Length; slot++)
                    {
                        if (spec[slot].SelectedIndex != 0)
                        {
                            int species = Randomizer.getRandomSpecies(ref sL, ref ctr);

                            if (smart)
                            {
                                int oldBST = personal[spec[slot].SelectedIndex].Take(6).Sum(b => (ushort)b);
                                int newBST = personal[species].Take(6).Sum(b => (ushort)b);
                                while (!(newBST * 4 / 5 < oldBST && newBST * 6 / 5 > oldBST))
                                {
                                    species = rand.Next(1, 722); newBST = personal[species].Take(6).Sum(b => (ushort)b);
                                }
                            }

                            spec[slot].SelectedIndex = species;

                            if (species == 666 || species == 665 || species == 664) // Vivillon
                            {
                                form[slot].Value = rnd32() % 20;
                            }
                            else if (species == 386) // Deoxys
                            {
                                form[slot].Value = rnd32() % 4;
                            }
                            else if (species == 201) // Unown
                            {
                                form[slot].Value = rnd32() % 28;
                            }
                            else if (species == 550) // Basculin
                            {
                                form[slot].Value = rnd32() % 2;
                            }
                            else if (species == 412 || species == 413) // Wormadam
                            {
                                form[slot].Value = rnd32() % 3;
                            }
                            else if (species == 422 || species == 423) // Gastrodon
                            {
                                form[slot].Value = rnd32() % 2;
                            }
                            else if (species == 585 || species == 586) // Sawsbuck
                            {
                                form[slot].Value = rnd32() % 4;
                            }
                            else if (species == 669 || species == 671) // Flabebe/Florges
                            {
                                form[slot].Value = rnd32() % 5;
                            }
                            else if (species == 670) // Floette
                            {
                                form[slot].Value = rnd32() % 6;
                            }
                            else if (species == 710 || species == 711) // Pumpkaboo
                            {
                                form[slot].Value = rnd32() % 4;
                            }
                            else
                            {
                                form[slot].Value = 0;
                            }
                        }
                    }
                    B_Save_Click(sender, e);
                }
                this.Enabled = true;
                Util.Alert("Randomized!");
            }
        }
Exemple #18
0
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            if (Util.Prompt(MessageBoxButtons.YesNo, "Randomize all?", "Cannot undo.") != DialogResult.Yes)
            {
                return;
            }

            Enabled = false;

            // Calculate % diff we will apply to each level
            decimal leveldiff = (100 + NUD_LevelAmp.Value) / 100;

            // Nonrepeating List Start
            int[] sL = Randomizer.getSpeciesList(CHK_G1.Checked, CHK_G2.Checked, CHK_G3.Checked,
                                                 CHK_G4.Checked, CHK_G5.Checked, CHK_G6.Checked, CHK_L.Checked, CHK_E.Checked);

            int ctr = 0;

            for (int i = 0; i < CB_LocationID.Items.Count; i++) // for every location
            {
                CB_LocationID.SelectedIndex = i;
                if (!hasData())
                {
                    continue;             // Don't randomize if doesn't have data.
                }
                // Assign Levels
                if (CHK_Level.Checked)
                {
                    for (int l = 0; l < max.Length; l++)
                    {
                        min[l].Value = max[l].Value = max[l].Value <= 1 ? max[l].Value : Math.Max(1, Math.Min(100, (int)(leveldiff * max[l].Value)));
                    }
                }

                for (int slot = 0; slot < max.Length; slot++)
                {
                    if (spec[slot].SelectedIndex == 0)
                    {
                        continue;
                    }

                    int species = Randomizer.getRandomSpecies(ref sL, ref ctr);

                    if (CHK_BST.Checked)
                    {
                        int oldBST = personal[spec[slot].SelectedIndex].Take(6).Sum(b => (ushort)b);
                        int newBST = personal[species].Take(6).Sum(b => (ushort)b);
                        while (!(newBST * 4 / 5 < oldBST && newBST * 6 / 5 > oldBST))
                        {
                            species = sL[rand.Next(1, sL.Length)]; newBST = personal[species].Take(6).Sum(b => (ushort)b);
                        }
                    }

                    spec[slot].SelectedIndex = species;
                    setRandomForm(slot, spec[slot].SelectedIndex);
                }
                B_Save_Click(sender, e);
            }
            Enabled = true;
            Util.Alert("Randomized!");
        }
Exemple #19
0
        // Randomization
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            if (Util.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings.") != DialogResult.Yes)
            {
                return;
            }

            Enabled = false;
            int setSkip = CHK_SOS.Checked ? 1 : 0;

            // Calculate % diff we will apply to each level
            decimal leveldiff = (100 + NUD_LevelAmp.Value) / 100;

            // Nonrepeating List Start
            int[] sL = Randomizer.getSpeciesList(CHK_G1.Checked, CHK_G2.Checked, CHK_G3.Checked,
                                                 CHK_G4.Checked, CHK_G5.Checked, CHK_G6.Checked, CHK_G7.Checked, CHK_L.Checked, CHK_E.Checked);

            int ctr = 0;

            foreach (var Map in Areas)
            {
                foreach (var Table in Map.Tables)
                {
                    if (CHK_Level.Checked)
                    {
                        Table.MinLevel = Math.Max(1, Math.Min(100, (int)(leveldiff * Table.MinLevel)));
                        Table.MaxLevel = Math.Max(1, Math.Min(100, (int)(leveldiff * Table.MaxLevel)));
                    }

                    foreach (var EncounterSet in Table.Encounters.Skip(setSkip)) // Skip regular slots if checked
                    {
                        foreach (var encounter in EncounterSet)
                        {
                            // Only modify slots that're used.
                            if (encounter.Species == 0)
                            {
                                continue;
                            }

                            if (!CHK_BST.Checked)
                            {
                                encounter.Species = (uint)Randomizer.getRandomSpecies(ref sL, ref ctr);
                            }
                            else
                            {
                                var old_ind = Main.SpeciesStat[encounter.Species].FormeIndex((int)encounter.Species, (int)encounter.Forme);
                                int oldBST  = Main.SpeciesStat[old_ind].BST;

                                int species = Randomizer.getRandomSpecies(ref sL, ref ctr);
                                int newBST  = Main.SpeciesStat[species].BST;
                                while (!(newBST * 4 / 5 < oldBST && newBST * 6 / 5 > oldBST))
                                {
                                    species = Randomizer.getRandomSpecies(ref sL, ref ctr);
                                    newBST  = Main.SpeciesStat[species].BST;
                                }
                                encounter.Species = (uint)species;
                            }
                            encounter.Forme = GetRandomForme((int)encounter.Species);
                        }
                    }

                    Table.Write();
                }
                encdata[Map.FileNumber] = getMapData(Map.Tables);
            }
            updatePanel(sender, e);
            Enabled = true;
            Util.Alert("Randomized!");
        }
Exemple #20
0
        // Randomization
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            if (Util.Prompt(MessageBoxButtons.YesNo, "Randomize all? Cannot undo.", "Double check Randomization settings.") != DialogResult.Yes)
            {
                return;
            }

            Enabled = false;
            int  slotStart;
            int  slotStop;
            bool copy = false;

            switch (CB_SlotRand.SelectedIndex)
            {
            default:     // All
                slotStart = 0;
                slotStop  = -1;
                break;

            case 1:     // Regular Only
                slotStart = 0;
                slotStop  = 1;
                break;

            case 2:     // SOS Only
                slotStart = 1;
                slotStop  = -1;
                break;

            case 3:     // Regular Only, Copy to SOS
                slotStart = 0;
                slotStop  = 1;
                copy      = true;
                break;
            }

            // Calculate % diff we will apply to each level
            decimal leveldiff = (100 + NUD_LevelAmp.Value) / 100;

            Randomizer rnd = new Randomizer(CHK_G1.Checked, CHK_G2.Checked, CHK_G3.Checked, CHK_G4.Checked, CHK_G5.Checked,
                                            CHK_G6.Checked, CHK_G7.Checked, CHK_L.Checked, CHK_E.Checked, Shedinja: true)
            {
                BST   = CHK_BST.Checked,
                Stats = Main.SpeciesStat
            };

            foreach (var Map in Areas)
            {
                foreach (var Table in Map.Tables)
                {
                    if (CHK_Level.Checked)
                    {
                        Table.MinLevel = Math.Max(1, Math.Min(100, (int)(leveldiff * Table.MinLevel)));
                        Table.MaxLevel = Math.Max(1, Math.Min(100, (int)(leveldiff * Table.MaxLevel)));
                    }

                    int end = slotStop < 0 ? Table.Encounters.Length : slotStop;
                    for (int s = slotStart; s < end; s++)
                    {
                        var EncounterSet = Table.Encounters[s];
                        foreach (var enc in EncounterSet.Where(enc => enc.Species != 0))
                        {
                            enc.Species = (uint)rnd.getRandomSpecies((int)enc.Species);
                            enc.Forme   = GetRandomForme((int)enc.Species);
                        }
                    }

                    if (copy) // copy row 0 to rest
                    {
                        var table = Table.Encounters;
                        var s0    = table[0];
                        for (int r = 1; r < table.Length; r++)
                        {
                            var slots = table[r];
                            for (int s = 0; s < slots.Length; s++)
                            {
                                slots[s].Species = s0[s].Species;
                                slots[s].Forme   = s0[s].Forme;
                            }
                        }
                    }

                    Table.Write();
                }
                encdata[Map.FileNumber] = getMapData(Map.Tables);
            }
            updatePanel(sender, e);
            Enabled = true;
            Util.Alert("Randomized!");
        }
Exemple #21
0
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            // gametext can be horribly broken if randomized
            if (Mode == "gametext" && DialogResult.Yes !=
                Util.Prompt(MessageBoxButtons.YesNo, "Randomizing Game Text is dangerous?", "Continue?"))
            {
                return;
            }

            // get if the user wants to randomize current text file or all files
            var dr = Util.Prompt(MessageBoxButtons.YesNoCancel,
                                 $"Yes: Randomize ALL{Environment.NewLine}No: Randomize current textfile{Environment.NewLine}Cancel: Abort");

            if (dr == DialogResult.Cancel)
            {
                return;
            }

            // get if pure shuffle or smart shuffle (no shuffle if variable present)
            var drs = Util.Prompt(MessageBoxButtons.YesNo,
                                  $"Smart shuffle:{Environment.NewLine}Yes: Shuffle if no Variable present{Environment.NewLine}No: Pure random!");

            if (drs == DialogResult.Cancel)
            {
                return;
            }

            bool all   = dr == DialogResult.Yes;
            bool smart = drs == DialogResult.Yes;

            // save current
            if (entry > -1)
            {
                files[entry] = getCurrentDGLines();
            }

            // single-entire looping
            int start = all ? 0 : entry;
            int end   = all ? files.Length - 1 : entry;

            // Gather strings
            List <string> strings = new List <string>();

            for (int i = start; i <= end; i++)
            {
                string[] data = files[i];
                strings.AddRange(smart
                    ? data.Where(line => !line.Contains("["))
                    : data);
            }

            // Shuffle up
            string[] pool = strings.ToArray();
            Util.Shuffle(pool);

            // Apply Text
            int ctr = 0;

            for (int i = start; i <= end; i++)
            {
                string[] data = files[i];

                for (int j = 0; j < data.Length; j++) // apply lines
                {
                    if (!smart || !data[j].Contains("["))
                    {
                        data[j] = pool[ctr++];
                    }
                }

                files[i] = data;
            }

            // Load current text file
            setStringsDataGridView(files[entry]);

            Util.Alert("Strings randomized!");
        }
Exemple #22
0
        private void saveARC(string path)
        {
            if (!Directory.Exists(path))
            {
                Util.Error("Input path is not a Folder", path); return;
            }
            string folderName = Path.GetFileName(path);

            if (folderName == null)
            {
                return;
            }
            string parentName = Directory.GetParent(path).FullName;
            int    type       = CB_Repack.SelectedIndex;

            switch (type)
            {
            case 0:     // AutoDetect
            {
                if (!folderName.Contains("_"))
                {
                    Util.Alert("Unable to autodetect pack type."); return;
                }

                if (folderName.Contains("_g"))
                {
                    goto case 1;
                }
                if (folderName.Contains("_d"))
                {
                    goto case 2;
                }
                // else
                goto case 3;
            }

            case 1:     // GARC Pack
            {
                if (threads > 0)
                {
                    Util.Alert("Please wait for all operations to finish first."); return;
                }
                DialogResult dr = Util.Prompt(MessageBoxButtons.YesNoCancel, "Format Selection:",
                                              "Yes: Sun/Moon (Version 6)\nNo: XY/ORAS (Version 4)");
                if (dr == DialogResult.Cancel)
                {
                    return;
                }

                var version = dr == DialogResult.Yes ? CTR.GARC.VER_6 : CTR.GARC.VER_4;
                new Thread(() =>
                    {
                        string outfolder = Directory.GetParent(path).FullName;
                        bool r           = CTR.GARC.garcPackMS(path, Path.Combine(outfolder, folderName + ".garc"), version, pBar1);
                        if (!r)
                        {
                            Util.Alert("Packing failed."); return;
                        }
                        // Delete path after repacking
                        if (CHK_Delete.Checked && Directory.Exists(path))
                        {
                            Directory.Delete(path, true);
                        }

                        System.Media.SystemSounds.Asterisk.Play();
                    }).Start();
                return;
            }

            case 2:     // DARC Pack (from existing if exists)
            {
                string oldFile = path.Replace("_d", "");
                if (File.Exists(Path.Combine(parentName, oldFile)))
                {
                    oldFile = Path.Combine(parentName, oldFile);
                }
                else if (File.Exists(Path.Combine(parentName, oldFile + ".bin")))
                {
                    oldFile = Path.Combine(parentName, oldFile + ".bin");
                }
                else if (File.Exists(Path.Combine(parentName, oldFile + ".darc")))
                {
                    oldFile = Path.Combine(parentName, oldFile + ".darc");
                }
                else
                {
                    oldFile = null;
                }

                bool r = CTR.DARC.files2darc(path, false, oldFile);
                if (!r)
                {
                    Util.Alert("Packing failed.");
                }
                break;
            }

            case 3:     // Mini Pack
            {
                // Get Folder Name
                string fileName = Path.GetFileName(path);
                if (fileName.Length < 3)
                {
                    Util.Error("Mini Folder name not valid:", path); return;
                }

                int    index   = fileName.LastIndexOf('_');
                string fileNum = fileName.Substring(0, index);
                string fileExt = fileName.Substring(index + 1);

                // Find old file for reference...
                string file;
                if (File.Exists(Path.Combine(parentName, fileNum + ".bin")))
                {
                    file = Path.Combine(parentName, fileNum + ".bin");
                }
                else if (File.Exists(Path.Combine(parentName, fileNum + "." + fileExt)))
                {
                    file = Path.Combine(parentName, fileNum + "." + fileExt);
                }
                else
                {
                    file = null;
                }

                byte[] oldData = file != null?File.ReadAllBytes(file) : null;

                bool r = CTR.mini.packMini2(path, fileExt, Path.Combine(parentName, fileNum + "." + fileExt));
                if (!r)
                {
                    Util.Alert("Packing failed.");
                    break;
                }

                // Check to see if the header size is different...
                if (oldData == null)     // No data to compare to.
                {
                    break;
                }

                byte[] newData = File.ReadAllBytes(Path.Combine(parentName, fileNum + "." + fileExt));
                if (newData[2] == oldData[2])
                {
                    int newPtr = BitConverter.ToInt32(newData, 4);
                    int oldPtr = BitConverter.ToInt32(oldData, 4);
                    if (newPtr != oldPtr)     // Header size is different. Prompt repointing.
                    {
                        if (DialogResult.Yes !=
                            Util.Prompt(MessageBoxButtons.YesNo, "Header size of existing file is nonstandard.",
                                        "Adjust newly packed file to have the same header size as old file? Data pointers will be updated accordingly."))
                        {
                            break;
                        }

                        // Fix pointers
                        byte[] update = CTR.mini.adjustMiniHeader(newData, oldPtr);
                        File.WriteAllBytes(Path.Combine(parentName, fileNum + "." + fileExt), update);
                    }
                }

                break;
            }

            default: Util.Alert("Repacking not implemented." + Environment.NewLine + path);
                return;
            }
            // Delete path after repacking
            if (CHK_Delete.Checked && Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }
            System.Media.SystemSounds.Asterisk.Play();
        }
Exemple #23
0
        private void B_Randomize_Click(object sender, EventArgs e)
        {
            if (Util.Prompt(MessageBoxButtons.YesNo, "Randomize all?", "Cannot undo.") != DialogResult.Yes)
            {
                return;
            }

            Enabled = false;

            // Calculate % diff we will apply to each level
            decimal leveldiff = (100 + NUD_LevelAmp.Value) / 100;

            // Nonrepeating List Start
            int[] sL = Randomizer.getSpeciesList(CHK_G1.Checked, CHK_G2.Checked, CHK_G3.Checked,
                                                 CHK_G4.Checked, CHK_G5.Checked, CHK_G6.Checked, CHK_L.Checked, CHK_E.Checked);

            int ctr = 0;

            for (int i = 0; i < CB_LocationID.Items.Count; i++) // for every location
            {
                CB_LocationID.SelectedIndex = i;
                if (!hasData())
                {
                    continue;             // Don't randomize if doesn't have data.
                }
                // Assign Levels
                if (CHK_Level.Checked)
                {
                    for (int l = 0; l < max.Length; l++)
                    {
                        min[l].Value = max[l].Value = (max[l].Value <= 1) ? max[l].Value : Math.Max(1, Math.Min(100, (int)((leveldiff) * max[l].Value)));
                    }
                }

                for (int slot = 0; slot < max.Length; slot++)
                {
                    if (spec[slot].SelectedIndex == 0)
                    {
                        continue;
                    }

                    int species = Randomizer.getRandomSpecies(ref sL, ref ctr);

                    if (CHK_BST.Checked)
                    {
                        int oldBST = personal[spec[slot].SelectedIndex].Take(6).Sum(b => (ushort)b);
                        int newBST = personal[species].Take(6).Sum(b => (ushort)b);
                        while (!(newBST * 4 / 5 < oldBST && newBST * 6 / 5 > oldBST))
                        {
                            species = sL[rand.Next(1, sL.Length)]; newBST = personal[species].Take(6).Sum(b => (ushort)b);
                        }
                    }

                    spec[slot].SelectedIndex = species;

                    if (species == 666 || species == 665 || species == 664) // Vivillon
                    {
                        form[slot].Value = rnd32() % 20;
                    }
                    else if (species == 386) // Deoxys
                    {
                        form[slot].Value = rnd32() % 4;
                    }
                    else if (species == 201) // Unown
                    {
                        form[slot].Value = rnd32() % 28;
                    }
                    else if (species == 550) // Basculin
                    {
                        form[slot].Value = rnd32() % 2;
                    }
                    else if (species == 412 || species == 413) // Wormadam
                    {
                        form[slot].Value = rnd32() % 3;
                    }
                    else if (species == 422 || species == 423) // Gastrodon
                    {
                        form[slot].Value = rnd32() % 2;
                    }
                    else if (species == 585 || species == 586) // Sawsbuck
                    {
                        form[slot].Value = rnd32() % 4;
                    }
                    else if (species == 669 || species == 671) // Flabebe/Florges
                    {
                        form[slot].Value = rnd32() % 5;
                    }
                    else if (species == 670) // Floette
                    {
                        form[slot].Value = rnd32() % 6;
                    }
                    else if (species == 710 || species == 711) // Pumpkaboo
                    {
                        form[slot].Value = rnd32() % 4;
                    }
                    else
                    {
                        form[slot].Value = 0;
                    }
                }
                B_Save_Click(sender, e);
            }
            Enabled = true;
            Util.Alert("Randomized!");
        }