Beispiel #1
0
        private void menuAddFolder_Click(object sender, RoutedEventArgs e)
        {
            using (CommonOpenFileDialog dialog = new CommonOpenFileDialog())
            {
                dialog.IsFolderPicker = true;

                if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
                {
                    DirectoryInfo directory = new DirectoryInfo(dialog.FileName);

                    using (XXHash64 xxHash = XXHash64.Create())
                    {
                        foreach (FileInfo fileInfo in directory.EnumerateFiles("*", SearchOption.AllDirectories))
                        {
                            string path       = fileInfo.FullName.Substring(directory.FullName.Length + 1);
                            ulong  hashedPath = BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(path.ToLower())), 0);

                            if (!StringDictionary.ContainsKey(hashedPath))
                            {
                                StringDictionary.Add(hashedPath, path);
                            }

                            this.WAD.AddEntry(hashedPath, File.ReadAllBytes(fileInfo.FullName), true);
                        }
                    }

                    Logger.Info("Added files from directory: " + dialog.FileName);
                }
            }
        }
 /// <summary>
 /// Removes a <see cref="WADEntry"/> Entry with the specified path
 /// </summary>
 /// <param name="path">The path of the <see cref="WADEntry"/> to remove</param>
 public void RemoveEntry(string path)
 {
     using (XXHash64 xxHash = XXHash64.Create())
     {
         RemoveEntry(BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(path)), 0));
     }
 }
Beispiel #3
0
        public string addFile(string filepath, string path)
        {
            if (mapEntries.ContainsKey(path))
            {
                return("");
            }

            try
            {
                var result = this.activeWad.AddEntry(path, File.ReadAllBytes(filepath), true);

                using (XXHash64 xxHash = XXHash64.Create())
                {
                    StringDictionary.Add(BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(path.ToLower())), 0), path);
                }

                mapEntries.Add(path, result);

                return(path);
            }
            catch (Exception e) {
                Console.WriteLine(e.Message);
                return("");
            }
        }
 /// <summary>
 /// Adds a new <see cref="EntryType.FileRedirection"/> <see cref="WADEntry"/> to this <see cref="WADFile"/>
 /// </summary>
 /// <param name="path">The virtual path of the file being added</param>
 /// <param name="fileRedirection">The file the game should load instead of this one</param>
 public void AddEntry(string path, string fileRedirection)
 {
     using (XXHash64 xxHash = XXHash64.Create())
     {
         AddEntry(BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(path.ToLower(new CultureInfo("en-US")))), 0), fileRedirection);
     }
 }
 /// <summary>
 /// Adds a new <see cref="WADEntry"/> to this <see cref="WADFile"/>
 /// </summary>
 /// <param name="path">The virtual path of the file being added</param>
 /// <param name="data">Data of file being added</param>
 /// <param name="compressedEntry">Whether the data needs to be GZip compressed inside WAD</param>
 public void AddEntry(string path, byte[] data, bool compressedEntry)
 {
     using (XXHash64 xxHash = XXHash64.Create())
     {
         AddEntry(BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(path.ToLower(new CultureInfo("en-US")))), 0), data, compressedEntry);
     }
 }
Beispiel #6
0
        private void menuAddFolder_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog()
            {
                ShowNewFolderButton = false
            };

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                DirectoryInfo directory = new DirectoryInfo(dialog.SelectedPath);

                using (XXHash64 xxHash = XXHash64.Create())
                {
                    foreach (FileInfo fileInfo in directory.EnumerateFiles("*", SearchOption.AllDirectories))
                    {
                        string path       = fileInfo.FullName.Substring(directory.FullName.Length + 1);
                        ulong  hashedPath = BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(path.ToLower())), 0);

                        if (!StringDictionary.ContainsKey(hashedPath))
                        {
                            StringDictionary.Add(hashedPath, path);
                        }

                        this.Wad.AddEntry(hashedPath, File.ReadAllBytes(fileInfo.FullName), true);
                    }
                }

                Logger.Info("Added files from directory: " + dialog.SelectedPath);
            }
        }
        public static List <WadResult> GenerateWADStrings(WADFile wad, List <WadResult> wadResults)
        {
            List <string> strings = new List <string>();

            foreach (WADEntry entry in wad.Entries.Where(x => x.Type != EntryType.FileRedirection))
            {
                byte[]         entryContent = entry.GetContent(true);
                LeagueFileType fileType     = Utilities.GetLeagueFileExtensionType(entryContent);

                if (fileType == LeagueFileType.BIN)
                {
                    BINFile bin = null;
                    try
                    {
                        bin = new BINFile(new MemoryStream(entryContent));
                        strings.AddRange(ProcessBINLinkedFiles(bin.LinkedFiles));
                        strings.AddRange(ProcessBINFile(bin));
                    }
                    catch (Exception excp)
                    {
                        throw new Exception(TAG + "解析wad文件失败,创建BIN文件失败...|" + excp.Message);
                    }
                }
            }
            Dictionary <ulong, string> stringDictionary = new Dictionary <ulong, string>();

            strings = strings.Distinct().ToList();
            using (XXHash64 xxHash = XXHash64.Create())
            {
                foreach (string fetchedString in strings)
                {
                    if (!string.IsNullOrEmpty(fetchedString))
                    {
                        // 计算路径的哈希值
                        byte[] b       = Encoding.ASCII.GetBytes(fetchedString.ToLower());
                        byte[] hashVal = xxHash.ComputeHash(b);
                        ulong  hash    = BitConverter.ToUInt64(hashVal, 0);
                        string hex     = BitConverter.ToString(hashVal, 0);

                        if (!stringDictionary.ContainsKey(hash))
                        {
                            stringDictionary.Add(hash, fetchedString);
                            WadResult wadResult = new WadResult();
                            wadResult.hash = hash;
                            wadResult.hex  = hex;
                            wadResult.name = fetchedString;
                            //wadResult.type = Utilities.GetLeagueFileExtensionType(b);
                            wadResults.Add(wadResult);
                        }
                    }
                }
            }
            GC.Collect();
            return(wadResults);
        }
Beispiel #8
0
        private void AddFile(string path, byte[] data, bool compressed, bool refresh)
        {
            using (XXHash64 xxHash = XXHash64.Create())
            {
                ulong hash = BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(path.ToLower())), 0);
                if (!StringDictionary.ContainsKey(hash))
                {
                    StringDictionary.Add(hash, path);
                }

                AddFile(hash, data, compressed, refresh);
            }
        }
Beispiel #9
0
        public static Dictionary <ulong, string> Generate(Wad wad)
        {
            Dictionary <ulong, string> hashtable = new Dictionary <ulong, string>();
            List <string> strings = new List <string>();

            foreach (WadEntry entry in wad.Entries.Values.Where(x => x.Type != WadEntryType.FileRedirection))
            {
                using Stream entryStream = entry.GetDataHandle().GetDecompressedStream();
                LeagueFileType fileType = LeagueUtilities.GetExtensionType(entryStream);

                if (fileType == LeagueFileType.BIN)
                {
                    BinTree bin = null;
                    try
                    {
                        bin = new BinTree(entryStream);
                    }
                    catch (Exception)
                    {
                    }

                    if (bin != null)
                    {
                        strings.AddRange(ProcessBinDependencies(bin.Dependencies));
                        strings.AddRange(ProcessBinTree(bin));
                    }
                }
                else if (IsLegacyDirList(entry.XXHash))
                {
                    strings.AddRange(ProcessLegacyDirList(entry));
                }
            }

            using (XXHash64 xxHash = XXHash64.Create())
            {
                foreach (string fetchedString in strings.Distinct())
                {
                    if (!string.IsNullOrEmpty(fetchedString))
                    {
                        ulong hash = BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(fetchedString.ToLower())), 0);

                        if (!hashtable.ContainsKey(hash))
                        {
                            hashtable.Add(hash, fetchedString);
                        }
                    }
                }
            }

            return(hashtable);
        }
        public static Dictionary <ulong, string> Generate(WADFile wad)
        {
            Dictionary <ulong, string> hashtable = new Dictionary <ulong, string>();
            List <string> strings = new List <string>();

            foreach (WADEntry entry in wad.Entries.Where(x => x.Type != EntryType.FileRedirection))
            {
                byte[]         entryContent = entry.GetContent(true);
                LeagueFileType fileType     = LeagueUtilities.GetExtension(entryContent);

                if (fileType == LeagueFileType.BIN)
                {
                    BINFile bin = null;
                    try
                    {
                        bin = new BINFile(new MemoryStream(entryContent));
                    }
                    catch (Exception)
                    {
                    }

                    if (bin != null)
                    {
                        strings.AddRange(ProcessBINLinkedFiles(bin.LinkedFiles));
                        strings.AddRange(ProcessBINFile(bin));
                    }
                }
                else if (IsLegacyDirList(entry.XXHash))
                {
                    strings.AddRange(ProcessLegacyDirList(entry));
                }
            }

            using (XXHash64 xxHash = XXHash64.Create())
            {
                foreach (string fetchedString in strings.Distinct())
                {
                    if (!string.IsNullOrEmpty(fetchedString))
                    {
                        ulong hash = BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(fetchedString.ToLower())), 0);

                        if (!hashtable.ContainsKey(hash))
                        {
                            hashtable.Add(hash, fetchedString);
                        }
                    }
                }
            }

            return(hashtable);
        }
Beispiel #11
0
        private void menuImportHashtable_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Title       = "Select the Hashtable files you want to load",
                Multiselect = true,
                Filter      = "Text Files (*.txt)|*.txt"
            };

            if (dialog.ShowDialog() == true)
            {
                try
                {
                    foreach (string fileName in dialog.FileNames)
                    {
                        foreach (string line in File.ReadAllLines(fileName))
                        {
                            string[] lineSplit = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                            if (ulong.TryParse(lineSplit[0], out ulong hash) && !StringDictionary.ContainsKey(hash))
                            {
                                StringDictionary.Add(ulong.Parse(lineSplit[0]), lineSplit[1]);
                            }
                            else
                            {
                                using (XXHash64 xxHash = XXHash64.Create())
                                {
                                    ulong key = BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(lineSplit[0].ToLower())), 0);
                                    if (!StringDictionary.ContainsKey(key))
                                    {
                                        StringDictionary.Add(key, lineSplit[0].ToLower());
                                    }
                                }
                            }
                        }

                        Logger.Info("Imported Hashtable from: " + fileName);
                    }
                }
                catch (Exception excp)
                {
                    Logging.LogException(Logger, "Failed to Import Hashtable", excp);
                    return;
                }

                CollectionViewSource.GetDefaultView(this.datagridWadEntries.ItemsSource).Refresh();
            }
        }
Beispiel #12
0
        public static void GenerateWADStrings(WADFile wad, Dictionary <ulong, string> stringDictionary)
        {
            List <string> strings = new List <string>();

            foreach (WADEntry entry in wad.Entries.Where(x => x.Type != EntryType.FileRedirection))
            {
                byte[]         entryContent = entry.GetContent(true);
                LeagueFileType fileType     = Utilities.GetLeagueFileExtensionType(entryContent);

                if (fileType == LeagueFileType.BIN)
                {
                    BINFile bin = null;
                    try
                    {
                        bin = new BINFile(new MemoryStream(entryContent));
                    }
                    catch (Exception excp)
                    {
                        Console.WriteLine(excp.Message);
                    }

                    if (bin != null)
                    {
                        strings.AddRange(ProcessBINLinkedFiles(bin.LinkedFiles));
                        strings = strings.Distinct().ToList();

                        strings.AddRange(ProcessBINFile(bin));
                    }
                }
            }

            using (XXHash64 xxHash = XXHash64.Create())
            {
                for (int i = 0; i < strings.Count; i++)
                {
                    string fetchedString = strings[i];
                    if (!string.IsNullOrEmpty(fetchedString))
                    {
                        ulong hash = BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(fetchedString.ToLower())), 0);

                        if (!stringDictionary.ContainsKey(hash))
                        {
                            stringDictionary.Add(hash, fetchedString);
                        }
                    }
                }
            }
        }
Beispiel #13
0
        private void menuImportHashtable_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog
            {
                Title            = "Select the Hashtable files you want to load",
                Multiselect      = true,
                Filter           = "Text Files (*.txt)|*.txt",
                InitialDirectory = (string)Config.Get("HashtableOpenDialogStartPath")
            };

            if (dialog.ShowDialog() == true)
            {
                try
                {
                    foreach (string fileName in dialog.FileNames)
                    {
                        foreach (string line in File.ReadAllLines(fileName))
                        {
                            using (XXHash64 xxHash = XXHash64.Create())
                            {
                                ulong hash = BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(line.ToLower())), 0);
                                if (!StringDictionary.ContainsKey(hash))
                                {
                                    StringDictionary.Add(hash, line);
                                }
                            }
                        }

                        Logger.Info("Imported Hashtable from: " + fileName);
                    }
                }
                catch (Exception excp)
                {
                    Logging.LogException(Logger, "Failed to Import Hashtable", excp);
                    return;
                }

                CollectionViewSource.GetDefaultView(this.datagridWadEntries.ItemsSource).Refresh();
            }
        }
Beispiel #14
0
        private void buttonAddFileAdd_Click(object sender, RoutedEventArgs e)
        {
            if (this.buttonAddFileOpen.Visibility == Visibility.Visible)
            {
                try
                {
                    this.Wad.AddEntry(this.textboxAddFilePath.Text, File.ReadAllBytes(this.textboxAddFileFilePath.Text), this.checkboxAddFileCompressed.IsChecked.Value);

                    using (XXHash64 xxHash = XXHash64.Create())
                    {
                        StringDictionary.Add(BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(this.textboxAddFilePath.Text.ToLower())), 0), this.textboxAddFilePath.Text);
                    }

                    CollectionViewSource.GetDefaultView(this.datagridWadEntries.ItemsSource).Refresh();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "Please choose a different Path", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
            else
            {
                try
                {
                    this.Wad.AddEntry(this.textboxAddFileFilePath.Text, this.textboxAddFilePath.Text);

                    using (XXHash64 xxHash = XXHash64.Create())
                    {
                        StringDictionary.Add(BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(this.textboxAddFileFilePath.Text.ToLower())), 0), this.textboxAddFileFilePath.Text);
                    }

                    CollectionViewSource.GetDefaultView(this.datagridWadEntries.ItemsSource).Refresh();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "Please choose a different Path", MessageBoxButton.OK, MessageBoxImage.Warning);
                }
            }
        }
Beispiel #15
0
        public void importHashTable(string fileName)
        {
            foreach (string line in File.ReadAllLines(fileName))
            {
                string[] lineSplit = line.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

                if (ulong.TryParse(lineSplit[0], out ulong hash) && !StringDictionary.ContainsKey(hash))
                {
                    StringDictionary.Add(ulong.Parse(lineSplit[0]), lineSplit[1]);
                }
                else
                {
                    using (XXHash64 xxHash = XXHash64.Create())
                    {
                        ulong key = BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(lineSplit[0].ToLower())), 0);
                        if (!StringDictionary.ContainsKey(key))
                        {
                            StringDictionary.Add(key, lineSplit[0].ToLower());
                        }
                    }
                }
            }
        }
Beispiel #16
0
        public List <String> importFolder(string folderPath)
        {
            var           list      = new List <string>();
            DirectoryInfo directory = new DirectoryInfo(folderPath);

            using (XXHash64 xxHash = XXHash64.Create())
            {
                foreach (FileInfo fileInfo in directory.EnumerateFiles("*", SearchOption.AllDirectories))
                {
                    string path       = fileInfo.FullName.Substring(directory.FullName.Length + 1);
                    ulong  hashedPath = BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(path.ToLower())), 0);

                    if (!StringDictionary.ContainsKey(hashedPath))
                    {
                        StringDictionary.Add(hashedPath, path);
                    }

                    var entry = this.activeWad.AddEntry(hashedPath, File.ReadAllBytes(fileInfo.FullName), true);
                    mapEntries.Add(path, entry);
                    list.Add(path);
                }
            }
            return(list);
        }
Beispiel #17
0
        private void menuCreateFromDirectory_Click(object sender, RoutedEventArgs e)
        {
            System.Windows.Forms.FolderBrowserDialog dialog = new System.Windows.Forms.FolderBrowserDialog()
            {
                ShowNewFolderButton = false
            };

            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.Wad?.Dispose();
                this.Wad         = new WADFile();
                StringDictionary = new Dictionary <ulong, string>();

                DirectoryInfo directory = new DirectoryInfo(dialog.SelectedPath);

                using (XXHash64 xxHash = XXHash64.Create())
                {
                    foreach (FileInfo fileInfo in directory.EnumerateFiles("*", SearchOption.AllDirectories))
                    {
                        string path = fileInfo.FullName.Substring(directory.FullName.Length + 1);
                        string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(path);
                        bool   hasUnknownPath           = fileNameWithoutExtension.All(c => "ABCDEF0123456789".Contains(c)) && fileNameWithoutExtension.Length <= 16;

                        if (hasUnknownPath)
                        {
                            ulong hashedPath = HexStringToUInt64(fileNameWithoutExtension);
                            this.Wad.AddEntry(hashedPath, File.ReadAllBytes(fileInfo.FullName), true);
                        }
                        else
                        {
                            ulong hashedPath = BitConverter.ToUInt64(xxHash.ComputeHash(Encoding.ASCII.GetBytes(path.ToLower())), 0);
                            if (!StringDictionary.ContainsKey(hashedPath))
                            {
                                StringDictionary.Add(hashedPath, path);
                            }

                            this.Wad.AddEntry(hashedPath, File.ReadAllBytes(fileInfo.FullName), true);
                        }
                    }
                }

                if ((bool)this.Config["GenerateWadDictionary"])
                {
                    try
                    {
                        WADHashGenerator.GenerateWADStrings(Logger, this.Wad, StringDictionary);
                    }
                    catch (Exception excp)
                    {
                        Logging.LogException(Logger, "Failed to Generate WAD String Dictionary", excp);
                    }
                }
                this.previewExpander.IsEnabled = true;

                this.menuSave.IsEnabled               = true;
                this.menuImportHashtable.IsEnabled    = true;
                this.menuExportHashtable.IsEnabled    = true;
                this.menuExportAll.IsEnabled          = true;
                this.menuAddFile.IsEnabled            = true;
                this.menuAddFileRedirection.IsEnabled = true;
                this.menuAddFolder.IsEnabled          = true;
                this.CurrentlySelectedEntry           = null;
                this.datagridWadEntries.ItemsSource   = this.Wad.Entries;

                Logger.Info("Created WAD file from directory: " + dialog.SelectedPath);
                CollectionViewSource.GetDefaultView(this.datagridWadEntries.ItemsSource).Refresh();
            }
        }