コード例 #1
0
        /// <summary>
        /// The games language files store items as hashes. This function will grab all strings in a all scripts in a directory
        /// and hash each string and them compare with a list of hashes supplied in the input box. Any matches get saved to a file STRINGS.txt in the directory
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void findHashFromStringsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            InputBox IB = new InputBox();

            if (!IB.ShowList("Input Hash", "Input hash to find", this))
            {
                return;
            }
            uint        hash;
            List <uint> Hashes = new List <uint>();

            foreach (string result in IB.ListValue)
            {
                if (result.StartsWith("0x"))
                {
                    if (uint.TryParse(result.Substring(2), System.Globalization.NumberStyles.HexNumber,
                                      new System.Globalization.CultureInfo("en-gb"), out hash))
                    {
                        Hashes.Add(hash);
                    }
                    else
                    {
                        MessageBox.Show($"Error converting {result} to hash value");
                    }
                }
                else
                {
                    if (uint.TryParse(result, out hash))
                    {
                        Hashes.Add(hash);
                    }
                    else
                    {
                        MessageBox.Show($"Error converting {result} to hash value");
                    }
                }
            }
            if (Hashes.Count == 0)
            {
                MessageBox.Show($"Error, no hashes inputted, please try again");
                return;
            }
            HashToFind          = Hashes.ToArray();
            CompileList         = new Queue <Tuple <string, bool> >();
            FoundStrings        = new List <Tuple <uint, string> >();
            Program.ThreadCount = 0;
            FolderSelectDialog fsd = new FolderSelectDialog();

            if (fsd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DateTime Start = DateTime.Now;
                this.Hide();

                foreach (string file in Directory.GetFiles(fsd.SelectedPath, "*.xsc"))
                {
                    CompileList.Enqueue(new Tuple <string, bool>(file, true));
                }
                foreach (string file in Directory.GetFiles(fsd.SelectedPath, "*.csc"))
                {
                    CompileList.Enqueue(new Tuple <string, bool>(file, true));
                }
                foreach (string file in Directory.GetFiles(fsd.SelectedPath, "*.ysc"))
                {
                    CompileList.Enqueue(new Tuple <string, bool>(file, false));
                }
                foreach (string file in Directory.GetFiles(fsd.SelectedPath, "*.ysc.full"))
                {
                    CompileList.Enqueue(new Tuple <string, bool>(file, false));
                }
                if (Program.Use_MultiThreading)
                {
                    for (int i = 0; i < Environment.ProcessorCount - 1; i++)
                    {
                        Program.ThreadCount++;
                        new System.Threading.Thread(FindString).Start();
                        System.Threading.Thread.Sleep(0);
                    }
                    Program.ThreadCount++;
                    FindString();
                    while (Program.ThreadCount > 0)
                    {
                        System.Threading.Thread.Sleep(10);
                    }
                }
                else
                {
                    Program.ThreadCount++;
                    FindString();
                }

                if (FoundStrings.Count == 0)
                {
                    updatestatus($"No Strings Found, Time taken: {DateTime.Now - Start}");
                }
                else
                {
                    updatestatus($"Found {FoundStrings.Count} strings, Time taken: {DateTime.Now - Start}");
                    FoundStrings.Sort((x, y) => x.Item1.CompareTo(y.Item1));
                    using (StreamWriter oFile = File.CreateText(Path.Combine(fsd.SelectedPath, "STRINGS.txt")))
                    {
                        foreach (Tuple <uint, string> Item in FoundStrings)
                        {
                            oFile.WriteLine($"0x{Utils.FormatHexHash(Item.Item1)} : \"{Item.Item2}\"");
                        }
                    }
                }
            }
            this.Show();
        }