예제 #1
0
        public static async Task PopulateMenu()
        {
            PopulateBase();

            await Task.Run(async() =>
            {
                if (string.IsNullOrEmpty(Properties.Settings.Default.PakPath))
                {
                    await Application.Current.Dispatcher.InvokeAsync(delegate
                    {
                        var launcher = new FLauncher();
                        bool?result  = launcher.ShowDialog();
                        if (result.HasValue && result.Value)
                        {
                            Properties.Settings.Default.PakPath = launcher.Path;
                            Properties.Settings.Default.Save();
                        }
                    });
                }

                // Add Pak Files
                if (Properties.Settings.Default.PakPath.EndsWith(".manifest"))
                {
                    ManifestInfo manifestInfo = await ManifestGrabber.TryGetLatestManifestInfo().ConfigureAwait(false);
                    byte[] manifestData       = await manifestInfo.DownloadManifestDataAsync().ConfigureAwait(false);
                    Manifest manifest         = new Manifest(manifestData, new ManifestOptions
                    {
                        ChunkBaseUri        = new Uri("http://download.epicgames.com/Builds/Fortnite/CloudDir/ChunksV3/", UriKind.Absolute),
                        ChunkCacheDirectory = Directory.CreateDirectory(Path.Combine(Properties.Settings.Default.OutputPath, "PakChunks"))
                    });
                    int pakFiles = 0;

                    foreach (FileManifest fileManifest in manifest.FileManifests)
                    {
                        if (!_pakFileRegex.IsMatch(fileManifest.Name))
                        {
                            continue;
                        }

                        var pakFileName       = fileManifest.Name.Replace('/', '\\');
                        PakFileReader pakFile = new PakFileReader(pakFileName, fileManifest.GetStream());

                        if (pakFiles++ == 0)
                        {
                            // define the current game thank to the pak path
                            Folders.SetGameName(pakFileName);

                            Globals.Game.Version    = pakFile.Info.Version;
                            Globals.Game.SubVersion = pakFile.Info.SubVersion;
                        }

                        await Application.Current.Dispatcher.InvokeAsync(delegate
                        {
                            MenuItems.pakFiles.Add(new PakMenuItemViewModel
                            {
                                PakFile   = pakFile,
                                IsEnabled = false
                            });
                        });
                    }
                }
                else if (Directory.Exists(Properties.Settings.Default.PakPath))
                {
                    // define the current game thank to the pak path
                    Folders.SetGameName(Properties.Settings.Default.PakPath);

                    string[] paks = Directory.GetFiles(Properties.Settings.Default.PakPath, "*.pak");
                    for (int i = 0; i < paks.Length; i++)
                    {
                        if (!Utils.Paks.IsFileReadLocked(new FileInfo(paks[i])))
                        {
                            PakFileReader pakFile = new PakFileReader(paks[i]);
                            DebugHelper.WriteLine("{0} {1} {2} {3}", "[FModel]", "[PAK]", "[Registering]", $"{pakFile.FileName} with GUID {pakFile.Info.EncryptionKeyGuid.Hex}");
                            if (i == 0)
                            {
                                Globals.Game.Version    = pakFile.Info.Version;
                                Globals.Game.SubVersion = pakFile.Info.SubVersion;
                            }

                            await Application.Current.Dispatcher.InvokeAsync(delegate
                            {
                                MenuItems.pakFiles.Add(new PakMenuItemViewModel
                                {
                                    PakFile   = pakFile,
                                    IsEnabled = false
                                });
                            });
                        }
                        else
                        {
                            FConsole.AppendText(string.Format(Properties.Resources.PakFileLocked, Path.GetFileNameWithoutExtension(paks[i])), FColors.Red, true);
                            DebugHelper.WriteLine("{0} {1} {2} {3}", "[FModel]", "[PAK]", "[Locked]", paks[i]);
                        }
                    }
                }
            });
        }
예제 #2
0
        public static async Task PopulateMenu()
        {
            PopulateBase();

            await Task.Run(async() =>
            {
                if (string.IsNullOrEmpty(Properties.Settings.Default.PakPath))
                {
                    await Application.Current.Dispatcher.InvokeAsync(delegate
                    {
                        var launcher = new FLauncher();
                        bool?result  = launcher.ShowDialog();
                        if (result.HasValue && result.Value)
                        {
                            Properties.Settings.Default.PakPath = launcher.Path;
                            Properties.Settings.Default.Save();
                        }
                    });
                }

                // Add Pak Files
                if (Properties.Settings.Default.PakPath.EndsWith("-fn.manifest"))
                {
                    ManifestInfo manifestInfo = await ManifestGrabber.TryGetLatestManifestInfo().ConfigureAwait(false);

                    if (manifestInfo == null)
                    {
                        throw new Exception("Failed to load latest manifest.");
                    }

                    DirectoryInfo chunksDir = Directory.CreateDirectory(Path.Combine(Properties.Settings.Default.OutputPath, "PakChunks"));
                    string manifestPath     = Path.Combine(chunksDir.FullName, manifestInfo.Filename);
                    byte[] manifestData;

                    if (File.Exists(manifestPath))
                    {
                        manifestData = await File.ReadAllBytesAsync(manifestPath);
                    }
                    else
                    {
                        manifestData = await manifestInfo.DownloadManifestDataAsync().ConfigureAwait(false);
                        await File.WriteAllBytesAsync(manifestPath, manifestData).ConfigureAwait(false);
                    }

                    Manifest manifest = new Manifest(manifestData, new ManifestOptions
                    {
                        ChunkBaseUri        = new Uri("http://download.epicgames.com/Builds/Fortnite/CloudDir/ChunksV3/", UriKind.Absolute),
                        ChunkCacheDirectory = Directory.CreateDirectory(Path.Combine(Properties.Settings.Default.OutputPath, "PakChunks"))
                    });
                    int pakFiles = 0;

                    foreach (FileManifest fileManifest in manifest.FileManifests)
                    {
                        if (!_pakFileRegex.IsMatch(fileManifest.Name))
                        {
                            continue;
                        }

                        var pakStream = fileManifest.GetStream();
                        if (pakStream.Length == 365)
                        {
                            continue;
                        }

                        var pakFileName = fileManifest.Name.Replace('/', '\\');
                        if (pakFileName.EndsWith(".pak"))
                        {
                            PakFileReader pakFile = new PakFileReader(pakFileName, pakStream);
                            if (pakFiles++ == 0)
                            {
                                // define the current game thank to the pak path
                                Folders.SetGameName(pakFileName);

                                Globals.Game.Version    = pakFile.Info.Version;
                                Globals.Game.SubVersion = pakFile.Info.SubVersion;
                            }

                            await Application.Current.Dispatcher.InvokeAsync(delegate
                            {
                                MenuItems.pakFiles.Add(new PakMenuItemViewModel
                                {
                                    PakFile   = pakFile,
                                    IsEnabled = false
                                });
                            });
                        }
                        else if (pakFileName.EndsWith(".ucas"))
                        {
                            var utocStream = manifest.FileManifests.FirstOrDefault(x => x.Name.Equals(fileManifest.Name.Replace(".ucas", ".utoc")));
                            var ioStore    = new FFileIoStoreReader(pakFileName.SubstringAfterLast('\\'), pakFileName.SubstringBeforeLast('\\'), utocStream.GetStream(), pakStream);
                            await Application.Current.Dispatcher.InvokeAsync(delegate
                            {
                                MenuItems.pakFiles.Add(new PakMenuItemViewModel
                                {
                                    IoStore   = ioStore,
                                    IsEnabled = false
                                });
                            });
                        }
                    }
                }
                else if (Properties.Settings.Default.PakPath.EndsWith("-val.manifest"))
                {
                    ValorantAPIManifest manifest = await ValorantAPIManifest.DownloadAndParse(Directory.CreateDirectory(Path.Combine(Properties.Settings.Default.OutputPath, "PakChunks"))).ConfigureAwait(false);

                    if (manifest == null)
                    {
                        throw new Exception("Failed to load latest manifest.");
                    }

                    for (int i = 0; i < manifest.Paks.Length; i++)
                    {
                        ValorantPak pak = manifest.Paks[i];

                        var pakFileName       = @$ "ShooterGame\Content\Paks\{pak.Name}";
                        PakFileReader pakFile = new PakFileReader(pakFileName, manifest.GetPakStream(i));

                        if (i == 0)
                        {
                            // define the current game thank to the pak path
                            Folders.SetGameName(pakFileName);

                            Globals.Game.Version    = pakFile.Info.Version;
                            Globals.Game.SubVersion = pakFile.Info.SubVersion;
                        }

                        await Application.Current.Dispatcher.InvokeAsync(delegate
                        {
                            MenuItems.pakFiles.Add(new PakMenuItemViewModel
                            {
                                PakFile   = pakFile,
                                IsEnabled = false
                            });
                        });
                    }
                }