/// <summary> /// We get the file list of currentPak, we find all files that matched our currentItem, for each result we get its index (it's used to get its data) /// Then we can use WriteFile to write each results with its data /// If currentPak is the same twice in a row, we do not try to get a new file list /// </summary> /// <param name="currentPak"></param> /// <param name="currentItem"></param> /// <returns> the path of the last created file (usually the uexp file but we don't care about the extension, so it's fine) </returns> public static string ExtractAsset(string currentPak, string currentItem) { if (currentPak != currentPakToCheck || myArray == null) { MyExtractor = new PakExtractor(Settings.Default.PAKsPath + "\\" + currentPak, MyKey); myArray = MyExtractor.GetFileList().ToArray(); } string[] results; if (currentItem.Contains(".")) { results = Array.FindAll(myArray, s => s.Contains("/" + currentItem)); } else { results = Array.FindAll(myArray, s => s.Contains("/" + currentItem + ".")); } string AssetPath = string.Empty; for (int i = 0; i < results.Length; i++) { int index = Array.IndexOf(myArray, results[i]); uint y = (uint)index; byte[] b = MyExtractor.GetData(y); AssetPath = WriteFile(currentItem, results[i], b).Replace("/", "\\"); } currentPakToCheck = currentPak; return(AssetPath); }
/// <summary> /// We get the file list of currentPak, we find all files that matched our currentItem, for each result we get its index (it's used to get its data) /// Then we can use WriteFile to write each results with its data /// If currentPak is the same twice in a row, we do not try to get a new file list /// </summary> /// <param name="currentPak"></param> /// <param name="currentItem"></param> /// <returns> the path of the last created file (usually the uexp file but we don't care about the extension, so it's fine) </returns> public static string ExtractAsset(string currentPak, string currentItem) { string pakGuid = ThePak.dynamicPaksList.Where(x => x.thePak == currentPak).Select(x => x.thePakGuid).FirstOrDefault(); string myKey = string.Empty; if (!string.IsNullOrEmpty(pakGuid) && pakGuid != "0-0-0-0") { myKey = DynamicKeysManager.AESEntries.Where(x => x.thePak == currentPak).Select(x => x.theKey).FirstOrDefault(); } else { myKey = Settings.Default.AESKey; } PakExtractor pakExtractor = ThePak.PaksExtractorDictionary[currentPak]; string[] pakFiles = ThePak.PaksFileArrayDictionary[pakExtractor]; string[] results = currentItem.Contains(".") ? Array.FindAll(pakFiles, s => s.Contains("/" + currentItem)) : Array.FindAll(pakFiles, s => s.Contains("/" + currentItem + ".")); string AssetPath = string.Empty; for (int i = 0; i < results.Length; i++) { if (results[i].Contains("DisplayAssets/EID_BlackMondayFemale_6HO4L.uasset")) { break; } int index = Array.IndexOf(pakFiles, results[i]); uint y = (uint)index; byte[] b = pakExtractor.GetData(y); AssetPath = WriteFile(results[i], b).Replace("/", "\\"); } pakExtractor = null; pakFiles = null; return(AssetPath); }
/// <summary> /// for each main paks we generate a file list /// if the main key used to generate the file list for each pak is working, we also load the localization file to get the translated version of all strings /// for the dynamic paks we check if the key exist in the AES Manager, if so, we do the same steps as a main pak /// </summary> /// <param name="theSinglePak"></param> /// <param name="loadAllPaKs"></param> public static void RegisterPaKsinDict(ToolStripItemClickedEventArgs theSinglePak = null, bool loadAllPaKs = false) { _sb = new StringBuilder(); bool bMainKeyWorking = false; for (int i = 0; i < ThePak.mainPaksList.Count; i++) { PakExtractor theExtractor = null; try { if (!string.IsNullOrWhiteSpace(Settings.Default.AESKey)) { theExtractor = new PakExtractor(Settings.Default.PAKsPath + "\\" + ThePak.mainPaksList[i].thePak, Settings.Default.AESKey); } else { if (theExtractor != null) { theExtractor.Dispose(); } break; } } catch (Exception ex) { if (string.Equals(ex.Message, "Extraction failed")) { DisplayError(); } else { DisplayEmergencyError(ex); return; } if (theExtractor != null) { theExtractor.Dispose(); } break; //if one of the main pak file doesn't work, all the other doesn't work either } if (theExtractor.GetFileList().ToArray() != null) { bMainKeyWorking = true; string mountPoint = theExtractor.GetMountPoint(); string[] fileListWithMountPoint = theExtractor.GetFileList().Select(s => s.Replace(s, mountPoint.Substring(9) + s)).ToArray(); ThePak.PaksExtractorDictionary.Add(ThePak.mainPaksList[i].thePak, theExtractor); ThePak.PaksFileArrayDictionary.Add(theExtractor, fileListWithMountPoint); RegisterInDict(ThePak.mainPaksList[i].thePak, fileListWithMountPoint, mountPoint, theSinglePak, loadAllPaKs); } } if (bMainKeyWorking) { LoadLocRes.LoadMySelectedLocRes(Settings.Default.IconLanguage); } for (int i = 0; i < ThePak.dynamicPaksList.Count; i++) { PakExtractor theExtractor = null; string pakName = DynamicKeysManager.AESEntries.Where(x => x.thePak == ThePak.dynamicPaksList[i].thePak).Select(x => x.thePak).FirstOrDefault(); string pakKey = DynamicKeysManager.AESEntries.Where(x => x.thePak == ThePak.dynamicPaksList[i].thePak).Select(x => x.theKey).FirstOrDefault(); if (!string.IsNullOrEmpty(pakName) && !string.IsNullOrEmpty(pakKey)) { try { theExtractor = new PakExtractor(Settings.Default.PAKsPath + "\\" + pakName, pakKey); } catch (Exception ex) { if (string.Equals(ex.Message, "Extraction failed")) { DisplayError(pakName, pakKey); } else { DisplayEmergencyError(ex); return; } if (theExtractor != null) { theExtractor.Dispose(); } continue; } if (theExtractor.GetFileList().ToArray() != null) { string mountPoint = theExtractor.GetMountPoint(); string[] fileListWithMountPoint = theExtractor.GetFileList().Select(s => s.Replace(s, mountPoint.Substring(9) + s)).ToArray(); ThePak.PaksExtractorDictionary.Add(ThePak.dynamicPaksList[i].thePak, theExtractor); ThePak.PaksFileArrayDictionary.Add(theExtractor, fileListWithMountPoint); RegisterInDict(ThePak.dynamicPaksList[i].thePak, fileListWithMountPoint, mountPoint, theSinglePak, loadAllPaKs); } } } if (loadAllPaKs) { File.WriteAllText(App.DefaultOutputPath + "\\FortnitePAKs.txt", _sb.ToString()); //File will always exist } new UpdateMyState("Building tree, please wait...", "Loading").ChangeProcessState(); GC.Collect(); }
public static void CreateBackupList() { PakExtractor extractor = null; StringBuilder sb = new StringBuilder(); for (int i = 0; i < ThePak.mainPaksList.Count; i++) { try { extractor = new PakExtractor(Settings.Default.PAKsPath + "\\" + ThePak.mainPaksList[i].thePak, Settings.Default.AESKey); } catch (Exception ex) { if (string.Equals(ex.Message, "Extraction failed")) { PakHelper.DisplayError(); } else { PakHelper.DisplayEmergencyError(ex); return; } if (extractor != null) { extractor.Dispose(); } break; //if one of the main pak file doesn't work, all the other doesn't work either } if (extractor.GetFileList().ToArray() != null) { string mountPoint = extractor.GetMountPoint(); string[] fileListWithMountPoint = extractor.GetFileList().Select(s => s.Replace(s, mountPoint.Substring(9) + s)).ToArray(); for (int ii = 0; ii < fileListWithMountPoint.Length; ii++) { sb.Append(fileListWithMountPoint[ii] + "\n"); } new UpdateMyState(".PAK mount point: " + mountPoint.Substring(9), "Waiting").ChangeProcessState(); } extractor.Dispose(); } for (int i = 0; i < ThePak.dynamicPaksList.Count; i++) { string pakName = DynamicKeysManager.AESEntries.Where(x => x.thePak == ThePak.dynamicPaksList[i].thePak).Select(x => x.thePak).FirstOrDefault(); string pakKey = DynamicKeysManager.AESEntries.Where(x => x.thePak == ThePak.dynamicPaksList[i].thePak).Select(x => x.theKey).FirstOrDefault(); if (!string.IsNullOrEmpty(pakName) && !string.IsNullOrEmpty(pakKey)) { try { extractor = new PakExtractor(Settings.Default.PAKsPath + "\\" + pakName, pakKey); } catch (Exception ex) { if (string.Equals(ex.Message, "Extraction failed")) { PakHelper.DisplayError(pakName, pakKey); } else { PakHelper.DisplayEmergencyError(ex); return; } if (extractor != null) { extractor.Dispose(); } continue; } if (extractor.GetFileList().ToArray() != null) { string mountPoint = extractor.GetMountPoint(); string[] fileListWithMountPoint = extractor.GetFileList().Select(s => s.Replace(s, mountPoint.Substring(9) + s)).ToArray(); for (int ii = 0; ii < fileListWithMountPoint.Length; ii++) { sb.Append(fileListWithMountPoint[ii] + "\n"); } new UpdateMyConsole("Backing up ", Color.Black).AppendToConsole(); new UpdateMyConsole(ThePak.dynamicPaksList[i].thePak, Color.CornflowerBlue, true).AppendToConsole(); } extractor.Dispose(); } } File.WriteAllText(App.DefaultOutputPath + "\\Backup" + Checking.BackupFileName, sb.ToString()); //File will always exist so we check the file size instead if (new FileInfo(App.DefaultOutputPath + "\\Backup" + Checking.BackupFileName).Length > 0) { new UpdateMyState("\\Backup" + Checking.BackupFileName + " successfully created", "Success").ChangeProcessState(); } else { File.Delete(App.DefaultOutputPath + "\\Backup" + Checking.BackupFileName); new UpdateMyState("Can't create " + Checking.BackupFileName.Substring(1), "Error").ChangeProcessState(); } }