Ejemplo n.º 1
0
        public override bool TryApplyPatch(out string failureReason)
        {
            string path = Directory.GetFiles(GameDirectory, Chunk + ".pak", SearchOption.AllDirectories).FirstOrDefault();

            if (path == null)
            {
                failureReason = $"Can't find pak file '{Chunk}.pak'";
                return(false);
            }

            try
            {
                using (var pak = Pak.OpenAsync(path).Result)
                {
                    var task = pak.DecryptAsync(Key);
                    task.Wait();
                }
            }
            catch (IncorrectEncryptionKeyException)
            {
                failureReason = "The given encryption key was not correct";
                return(false);
            }

            failureReason = null;
            return(true);
        }
Ejemplo n.º 2
0
        public async Task OpenPakAsync(StorageFile file)
        {
            try
            {
                var fileStream = (await file.OpenAsync(FileAccessMode.ReadWrite)).AsStream();
                Pak pak        = await Pak.OpenAsync(fileStream);

                if (pak.IsIndexEncrypted)
                {
                    // If the pak is encrypted, ask for the key and attempt to decrypt it.
                    bool decryptSuccessful   = false;
                    bool isSubsequentAttempt = false;
                    while (!decryptSuccessful)
                    {
                        var decryptDialog = new DecryptPakDialog(isSubsequentAttempt);
                        if (await decryptDialog.ShowAsync() == ContentDialogResult.Primary)
                        {
                            try
                            {
                                Entries = await pak.GetEntriesAsync(decryptDialog.EncryptionKey);

                                decryptSuccessful = true;
                                EncryptionKey     = decryptDialog.EncryptionKey;
                            }
                            catch (IncorrectEncryptionKeyException)
                            {
                                isSubsequentAttempt = true;
                            }
                        }
                        else
                        {
                            return; // No encryption key provided, we're not opening this file.
                        }
                    }
                }
                else
                {
                    Entries = await pak.GetEntriesAsync();
                }

                CurrentPak = pak;
                ApplicationView.GetForCurrentView().Title = file.Path;
                StatusText = $"{Entries.Count} files";
            }
            catch (MagicNumberMismatchException)
            {
                await(new MessageDialog("This isn't a pak file.")).ShowAsync();
            }
            catch (UnsupportedVersionException)
            {
                await(new MessageDialog("This pak is based on a version that isn't supported at this time.")).ShowAsync();
            }
        }
Ejemplo n.º 3
0
        public override bool TryApplyPatch(out string failureReason)
        {
            string path = Directory.GetFiles(GameDirectory, Chunk + ".pak", SearchOption.AllDirectories).FirstOrDefault();

            if (path == null)
            {
                failureReason = $"Can't find pak file '{Chunk}.pak'";
                return(false);
            }

            var replacementFile = PatchFile.GetEntry(ReplacementFileName);

            if (replacementFile == null)
            {
                failureReason = $"Missing file '{ReplacementFileName}' in patch";
                return(false);
            }

            using (var pak = Pak.OpenAsync(path).Result)
            {
                if (pak.IsIndexEncrypted)
                {
                    failureReason = "Pak must be decrypted first";
                    return(false);
                }

                foreach (var entry in pak.GetEntriesAsync().Result)
                {
                    if (entry.FileName == FileName)
                    {
                        using (var stream = replacementFile.Open())
                            using (var ms = new MemoryStream())
                            {
                                stream.CopyTo(ms);

                                if (ms.Length > entry.Size)
                                {
                                    failureReason = "Replacement file is bigger than the original file";
                                    return(false);
                                }
                                else if (ms.Length < entry.Size)
                                {
                                    long padSize = entry.Size - ms.Length;
                                    for (long i = 0; i < padSize; i++)
                                    {
                                        ms.WriteByte(Padding == PaddingType.Spaces ? (byte)0x20 : (byte)0x00);
                                    }
                                }

                                ms.Seek(0, SeekOrigin.Begin);
                                var task = pak.SwapEntryAsync(entry, ms);
                                task.Wait();

                                failureReason = "";
                                return(true);
                            }
                    }
                }

                failureReason = $"Cannot find file '{FileName}' in pak '{Chunk}.pak'";
                return(false);
            }
        }