Exemplo n.º 1
0
        private static void PopulateDict(string folder, string fileName, string lang)
        {
            string path = $"{folder}{fileName}/{lang}/{fileName}.locres";

            DebugHelper.WriteLine(".PAKs: Loading " + path + " as the translation file");

            if (HotfixLocResDict == null)
            {
                SetHotfixedLocResDict();
            }                                                          //once, no need to do more

            Dictionary <string, Dictionary <string, string> > brFinalDict  = new Dictionary <string, Dictionary <string, string> >();
            Dictionary <string, Dictionary <string, string> > stwFinalDict = new Dictionary <string, Dictionary <string, string> >();

            foreach (FPakEntry[] PAKsFileInfos in PAKEntries.PAKToDisplay.Values)
            {
                IEnumerable <string> locresFilesPath = PAKsFileInfos.Where(x => x.Name.StartsWith(folder + fileName) && x.Name.Contains($"/{lang}/") && x.Name.EndsWith(".locres")).Select(x => x.Name);
                if (locresFilesPath.Any())
                {
                    foreach (string file in locresFilesPath)
                    {
                        var dict = GetLocResDict(file);
                        foreach (var namespac in dict)
                        {
                            if (!brFinalDict.ContainsKey(namespac.Key))
                            {
                                brFinalDict.Add(namespac.Key, new Dictionary <string, string>());
                            }

                            foreach (var key in namespac.Value)
                            {
                                brFinalDict[namespac.Key].Add(key.Key, key.Value);
                            }
                        }
                    }
                }
                locresFilesPath = PAKsFileInfos.Where(x => x.Name.StartsWith(folder + "Game_StW") && x.Name.Contains($"/{lang}/") && x.Name.EndsWith(".locres")).Select(x => x.Name);
                if (locresFilesPath.Any())
                {
                    foreach (string file in locresFilesPath)
                    {
                        var dict = GetLocResDict(file);
                        foreach (var namespac in dict)
                        {
                            if (!stwFinalDict.ContainsKey(namespac.Key))
                            {
                                stwFinalDict.Add(namespac.Key, new Dictionary <string, string>());
                            }

                            foreach (var key in namespac.Value)
                            {
                                stwFinalDict[namespac.Key].Add(key.Key, key.Value);
                            }
                        }
                    }
                }
            }
            BRLocResDict  = brFinalDict;
            STWLocResDict = stwFinalDict;
        }
Exemplo n.º 2
0
        public static async Task PopulateListBox(TreeViewItem sItem)
        {
            FilesListWithoutPath = null;
            FWindow.FMain.ListBox_Main.Items.Clear();
            FWindow.FMain.FilterTextBox_Main.Text = string.Empty;

            string path = TreeViewUtility.GetFullPath(sItem);

            FilesListWithoutPath = new List <IEnumerable <string> >();
            if (!string.IsNullOrEmpty(FWindow.FCurrentPAK))
            {
                IEnumerable <string> filesWithoutPath = PAKEntries.PAKToDisplay[FWindow.FCurrentPAK]
                                                        .Where(x => x.Name.Contains(path + "/" + Path.GetFileName(x.Name)))
                                                        .Select(x => Path.GetFileName(x.Name));

                if (filesWithoutPath != null)
                {
                    FilesListWithoutPath.Add(filesWithoutPath);
                }
            }
            else
            {
                foreach (FPakEntry[] PAKsFileInfos in PAKEntries.PAKToDisplay.Values)
                {
                    IEnumerable <string> filesWithoutPath = PAKsFileInfos
                                                            .Where(x => x.Name.Contains(path + "/" + Path.GetFileName(x.Name)))
                                                            .Select(x => Path.GetFileName(x.Name));

                    if (filesWithoutPath != null)
                    {
                        FilesListWithoutPath.Add(filesWithoutPath);
                    }
                }
            }

            if (FilesListWithoutPath != null && FilesListWithoutPath.Any())
            {
                await Task.Run(() =>
                {
                    FillMeThisPls();
                }).ContinueWith(TheTask =>
                {
                    TasksUtility.TaskCompleted(TheTask.Exception);
                });
            }

            FWindow.FMain.Button_Extract.IsEnabled = FWindow.FMain.ListBox_Main.SelectedIndex >= 0;
        }
Exemplo n.º 3
0
        public static async Task ExtractFoldersAndSub(string path)
        {
            new UpdateMyProcessEvents("", "").Update();
            FWindow.FMain.Button_Extract.IsEnabled     = false;
            FWindow.FMain.Button_Stop.IsEnabled        = true;
            FWindow.FMain.AssetPropertiesBox_Main.Text = string.Empty;
            FWindow.FMain.AssetPropertiesBox_Main.SyntaxHighlighting = ResourceLoader.LoadHighlightingDefinition("Json.xshd");
            FWindow.FMain.ImageBox_Main.Source = null;

            List <IEnumerable <string> > assetList = new List <IEnumerable <string> >();

            if (!string.IsNullOrEmpty(FWindow.FCurrentPAK))
            {
                IEnumerable <string> files = PAKEntries.PAKToDisplay[FWindow.FCurrentPAK]
                                             .Where(x => x.Name.StartsWith(path + "/"))
                                             .Select(x => x.Name);

                if (files != null)
                {
                    assetList.Add(files);
                }
            }
            else
            {
                foreach (FPakEntry[] PAKsFileInfos in PAKEntries.PAKToDisplay.Values)
                {
                    IEnumerable <string> files = PAKsFileInfos
                                                 .Where(x => x.Name.StartsWith(path + "/"))
                                                 .Select(x => x.Name);

                    if (files != null)
                    {
                        assetList.Add(files);
                    }
                }
            }

            TasksUtility.CancellableTaskTokenSource = new CancellationTokenSource();
            CancellationToken cToken = TasksUtility.CancellableTaskTokenSource.Token;
            await Task.Run(() =>
            {
                isRunning = true;
                DebugHelper.WriteLine("Assets: User is extracting everything in " + path);
                foreach (IEnumerable <string> filesFromOnePak in assetList)
                {
                    foreach (string asset in filesFromOnePak.OrderBy(s => s))
                    {
                        cToken.ThrowIfCancellationRequested(); //if clicked on 'Stop' it breaks at the following item

                        string target;
                        if (asset.EndsWith(".uexp") || asset.EndsWith(".ubulk"))
                        {
                            continue;
                        }
                        else if (!asset.EndsWith(".uasset"))
                        {
                            target = asset; //ini uproject locres etc
                        }
                        else
                        {
                            target = asset.Substring(0, asset.LastIndexOf(".")); //uassets
                        }

                        while (!string.Equals(FWindow.FCurrentAsset, Path.GetFileName(target)))
                        {
                            FWindow.FCurrentAsset = Path.GetFileName(target);
                        }
                        LoadAsset(target);
                    }
                }
            }, cToken).ContinueWith(TheTask =>
            {
                TasksUtility.TaskCompleted(TheTask.Exception);
                TasksUtility.CancellableTaskTokenSource.Dispose();
                isRunning = false;
            });

            FWindow.FMain.Button_Extract.IsEnabled = true;
            FWindow.FMain.Button_Stop.IsEnabled    = false;
        }
Exemplo n.º 4
0
        public static async Task ExtractUpdateMode()
        {
            new UpdateMyProcessEvents("", "").Update();
            FWindow.FMain.Button_Extract.IsEnabled     = false;
            FWindow.FMain.Button_Stop.IsEnabled        = true;
            FWindow.FMain.AssetPropertiesBox_Main.Text = string.Empty;
            FWindow.FMain.AssetPropertiesBox_Main.SyntaxHighlighting = ResourceLoader.LoadHighlightingDefinition("Json.xshd");
            FWindow.FMain.ImageBox_Main.Source = null;
            bool sound = FProp.Default.FOpenSounds;

            FProp.Default.FOpenSounds = false;

            List <IEnumerable <string> > assetList = new List <IEnumerable <string> >();

            foreach (FPakEntry[] PAKsFileInfos in PAKEntries.PAKToDisplay.Values)
            {
                IEnumerable <string> files = PAKsFileInfos
                                             .Where(x => Forms.FModel_UpdateMode.AssetsEntriesDict.Any(c => bool.Parse(c.Value["isChecked"]) && x.Name.StartsWith(c.Value["Path"])))
                                             .Select(x => x.Name);

                if (files != null)
                {
                    assetList.Add(files);
                }
            }

            TasksUtility.CancellableTaskTokenSource = new CancellationTokenSource();
            CancellationToken cToken = TasksUtility.CancellableTaskTokenSource.Token;
            await Task.Run(() =>
            {
                isRunning = true;
                foreach (IEnumerable <string> filesFromOnePak in assetList)
                {
                    foreach (string asset in filesFromOnePak.OrderBy(s => s))
                    {
                        cToken.ThrowIfCancellationRequested(); //if clicked on 'Stop' it breaks at the following item

                        string target;
                        if (asset.EndsWith(".uexp") || asset.EndsWith(".ubulk"))
                        {
                            continue;
                        }
                        else if (!asset.EndsWith(".uasset"))
                        {
                            target = asset; //ini uproject locres etc
                        }
                        else
                        {
                            target = asset.Substring(0, asset.LastIndexOf(".")); //uassets
                        }

                        while (!string.Equals(FWindow.FCurrentAsset, Path.GetFileName(target)))
                        {
                            FWindow.FCurrentAsset = Path.GetFileName(target);
                        }

                        try
                        {
                            LoadAsset(target);
                        }
                        catch (System.Exception ex)
                        {
                            new UpdateMyConsole(ex.Message, CColors.Red, true).Append();
                        }
                    }
                }
            }, cToken).ContinueWith(TheTask =>
            {
                TasksUtility.TaskCompleted(TheTask.Exception);
                TasksUtility.CancellableTaskTokenSource.Dispose();
                isRunning = false;
            });

            FWindow.FMain.MI_Auto_Save_Images.IsChecked = false;
            FWindow.FMain.Button_Extract.IsEnabled      = true;
            FWindow.FMain.Button_Stop.IsEnabled         = false;
            FWindow.FMain.MI_Auto_Save_Images.IsChecked = false;
            FProp.Default.FOpenSounds = sound;
            new UpdateMyProcessEvents("All assets have been extracted successfully", "Success").Update();
        }
Exemplo n.º 5
0
        private static async Task LoadBackupFile(bool updateMode = false)
        {
            OpenFileDialog openFiledialog = new OpenFileDialog();

            openFiledialog.Title            = "Choose your Backup File";
            openFiledialog.InitialDirectory = FProp.Default.FOutput_Path + "\\Backups\\";
            openFiledialog.Multiselect      = false;
            openFiledialog.Filter           = "FBKP Files (*.fbkp)|*.fbkp|All Files (*.*)|*.*";
            if (openFiledialog.ShowDialog() == true)
            {
                DebugHelper.WriteLine($".PAKs: Loading {openFiledialog.FileName} as the backup file");
                new UpdateMyProcessEvents("Comparing Files", "Waiting").Update();

                FPakEntry[] BackupEntries;
                using (FileStream fileStream = new FileStream(openFiledialog.FileName, FileMode.Open))
                    using (BinaryReader reader = new BinaryReader(fileStream))
                    {
                        DebugHelper.WriteLine(".PAKs: Populating FPakEntry[] for the backup file");

                        List <FPakEntry> entries = new List <FPakEntry>();
                        while (reader.BaseStream.Position < reader.BaseStream.Length)
                        {
                            // we must follow this order
                            long   offset                 = reader.ReadInt64();
                            long   size                   = reader.ReadInt64();
                            long   uncompressedSize       = reader.ReadInt64();
                            bool   encrypted              = reader.ReadBoolean();
                            long   structSize             = reader.ReadInt32();
                            string name                   = reader.ReadString();
                            long   compressionMethodIndex = reader.ReadInt32();

                            // we actually only need name and uncompressedSize to compare
                            FPakEntry entry = new FPakEntry(name, offset, size, uncompressedSize, new byte[20], null, 0, 0, 0);
                            entries.Add(entry);
                        }
                        BackupEntries = entries.ToArray();
                    }

                if (BackupEntries.Any())
                {
                    DebugHelper.WriteLine(".PAKs: FPakEntry[] for the backup file is populated");

                    List <FPakEntry> LocalEntries = new List <FPakEntry>();
                    foreach (FPakEntry[] PAKsFileInfos in PAKEntries.PAKToDisplay.Values)
                    {
                        PAKsFileInfos.ToList().ForEach(x => LocalEntries.Add(x));
                    }
                    PAKEntries.PAKToDisplay.Clear();
                    DebugHelper.WriteLine(".PAKs: FPakEntry[] for the local .PAKs is populated");

                    //FILTER WITH THE OVERRIDED EQUALS METHOD (CHECKING FILE NAME AND FILE UNCOMPRESSED SIZE)
                    DebugHelper.WriteLine($".PAKs: Comparing...\t File Size Check: {FProp.Default.FDiffFileSize}");
                    IEnumerable <FPakEntry> newAssets = LocalEntries.Except(BackupEntries);
                    DebugHelper.WriteLine(".PAKs: Compared");

                    //ADD TO TREE
                    DebugHelper.WriteLine(".PAKs: Filling Treeview with differentiated assets");
                    foreach (FPakEntry entry in newAssets)
                    {
                        string onlyFolders = entry.Name.Substring(0, entry.Name.LastIndexOf('/'));
                        await FWindow.FMain.Dispatcher.InvokeAsync(() =>
                        {
                            TreeViewUtility.PopulateTreeView(srt, onlyFolders.Substring(1));
                        });
                    }

                    //ONLY LOAD THE DIFFERENCE WHEN WE CLICK ON A FOLDER
                    FWindow.FCurrentPAK = "ComparedPAK-WindowsClient.pak";
                    PAKEntries.PAKToDisplay.Add("ComparedPAK-WindowsClient.pak", newAssets.ToArray());
                    await FWindow.FMain.Dispatcher.InvokeAsync(() =>
                    {
                        FWindow.FMain.ViewModel = srt;
                    });

                    DebugHelper.WriteLine(".PAKs: Treeview filled");

                    await FWindow.FMain.Dispatcher.InvokeAsync(() =>
                    {
                        FWindow.FMain.TreeView_Main.IsEnabled     = true;
                        FWindow.FMain.MI_LoadAllPAKs.IsEnabled    = true;
                        FWindow.FMain.MI_BackupPAKs.IsEnabled     = true;
                        FWindow.FMain.MI_DifferenceMode.IsEnabled = true;
                        if (updateMode)
                        {
                            FWindow.FMain.MI_UpdateMode.IsEnabled = true;
                        }
                    });

                    //PRINT REMOVED IF NO FILE SIZE CHECK
                    if (!FProp.Default.FDiffFileSize)
                    {
                        DebugHelper.WriteLine(".PAKs: Checking deleted items");
                        new UpdateMyProcessEvents("Checking deleted items", "Waiting").Update();
                        IEnumerable <FPakEntry> removedAssets = BackupEntries.Except(LocalEntries.ToArray());

                        List <string> removedItems = new List <string>();
                        foreach (FPakEntry entry in removedAssets)
                        {
                            if (entry.Name.StartsWith("/FortniteGame/Content/Athena/Items/Cosmetics/"))
                            {
                                removedItems.Add(entry.Name.Substring(0, entry.Name.LastIndexOf(".")));
                            }
                        }

                        if (removedItems.Count > 0)
                        {
                            DebugHelper.WriteLine(".PAKs: Items Removed/Renamed:");
                            new UpdateMyConsole("Items Removed/Renamed:", CColors.Red, true).Append();
                            removedItems.Distinct().ToList().ForEach(e => {
                                new UpdateMyConsole($"    - {e.Substring(1)}", CColors.White, true).Append();
                                DebugHelper.WriteLine($"    - {e.Substring(1)}");
                            });
                        }
                    }

                    DebugHelper.WriteLine(".PAKs: PAK files have been compared successfully");
                    new UpdateMyProcessEvents("All PAK files have been compared successfully", "Success").Update();
                    umIsOk = true;
                }
                else
                {
                    DebugHelper.WriteLine(".PAKs: FPakEntry[] for the backup file is empty");
                }
            }
            else
            {
                DebugHelper.WriteLine(".PAKs: User canceled when he got asked to select a backup file");

                new UpdateMyConsole("You change your mind pretty fast but it's fine ", CColors.White).Append();
                new UpdateMyConsole("all paks have been loaded instead", CColors.Blue, true).Append();
                FillTreeView(true);

                await FWindow.FMain.Dispatcher.InvokeAsync(() =>
                {
                    FWindow.FMain.TreeView_Main.IsEnabled     = true;
                    FWindow.FMain.MI_LoadAllPAKs.IsEnabled    = true;
                    FWindow.FMain.MI_BackupPAKs.IsEnabled     = true;
                    FWindow.FMain.MI_DifferenceMode.IsEnabled = true;
                    FWindow.FMain.MI_DifferenceMode.IsChecked = false;
                    if (updateMode)
                    {
                        FWindow.FMain.MI_UpdateMode.IsEnabled = true;
                        FWindow.FMain.MI_UpdateMode.IsChecked = false;
                    }
                });
            }
        }
Exemplo n.º 6
0
        private static async Task LoadBackupFile()
        {
            OpenFileDialog openFiledialog = new OpenFileDialog();

            openFiledialog.Title            = "Choose your Backup File";
            openFiledialog.InitialDirectory = FProp.Default.FOutput_Path + "\\Backups\\";
            openFiledialog.Multiselect      = false;
            openFiledialog.Filter           = "FBKP Files (*.fbkp)|*.fbkp|All Files (*.*)|*.*";
            if (openFiledialog.ShowDialog() == true)
            {
                new UpdateMyProcessEvents("Comparing Files", "Waiting").Update();

                FPakEntry[] BackupEntries;
                using (FileStream fileStream = new FileStream(openFiledialog.FileName, FileMode.Open))
                    using (BinaryReader reader = new BinaryReader(fileStream))
                    {
                        List <FPakEntry> entries = new List <FPakEntry>();
                        while (reader.BaseStream.Position < reader.BaseStream.Length)
                        {
                            FPakEntry entry = new FPakEntry();
                            entry.Pos               = reader.ReadInt64();
                            entry.Size              = reader.ReadInt64();
                            entry.UncompressedSize  = reader.ReadInt64();
                            entry.Encrypted         = reader.ReadBoolean();
                            entry.StructSize        = reader.ReadInt32();
                            entry.Name              = reader.ReadString();
                            entry.CompressionMethod = reader.ReadInt32();
                            entries.Add(entry);
                        }
                        BackupEntries = entries.ToArray();
                    }

                if (BackupEntries.Any())
                {
                    List <FPakEntry> LocalEntries = new List <FPakEntry>();
                    foreach (FPakEntry[] PAKsFileInfos in PAKEntries.PAKToDisplay.Values)
                    {
                        PAKsFileInfos.ToList().ForEach(x => LocalEntries.Add(x));
                    }
                    PAKEntries.PAKToDisplay.Clear();

                    //FILTER WITH THE OVERRIDED EQUALS METHOD (CHECKING FILE NAME AND FILE UNCOMPRESSED SIZE)
                    IEnumerable <FPakEntry> newAssets = LocalEntries.ToArray().Except(BackupEntries);

                    //ADD TO TREE
                    foreach (FPakEntry entry in newAssets)
                    {
                        string onlyFolders = entry.Name.Substring(0, entry.Name.LastIndexOf('/'));
                        await FWindow.FMain.Dispatcher.InvokeAsync(() =>
                        {
                            TreeViewUtility.PopulateTreeView(srt, onlyFolders.Substring(1));
                        });
                    }

                    //ONLY LOAD THE DIFFERENCE WHEN WE CLICK ON A FOLDER
                    FWindow.FCurrentPAK = "ComparedPAK-WindowsClient.pak";
                    PAKEntries.PAKToDisplay.Add("ComparedPAK-WindowsClient.pak", newAssets.ToArray());
                    await FWindow.FMain.Dispatcher.InvokeAsync(() =>
                    {
                        FWindow.FMain.ViewModel = srt;
                    });

                    new UpdateMyProcessEvents("All PAK files have been compared successfully", "Success").Update();
                }
            }
            else
            {
                new UpdateMyConsole("You change your mind pretty fast but it's fine ", CColors.White).Append();
                new UpdateMyConsole("all paks have been loaded instead", CColors.Blue, true).Append();
                FillTreeView(true);
            }
        }