Example #1
0
        /* Create a PAK2 archive from a specified directory */
        private void createPAK2FromDirectoryToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog FolderToParse = new FolderBrowserDialog();

            if (FolderToParse.ShowDialog() == DialogResult.OK)
            {
                List <string> FilesToAdd = new List <string>();
                ListAllFiles(FolderToParse.SelectedPath, FilesToAdd);

                MessageBox.Show("Please select a location to save the new PAK2 archive.", "Select output location...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                SaveFileDialog PathToPAK2 = new SaveFileDialog();
                PathToPAK2.Filter = "PAK2 Archive|*.PAK";
                if (PathToPAK2.ShowDialog() == DialogResult.OK)
                {
                    Cursor.Current = Cursors.WaitCursor;

                    PAK2 NewArchive = new PAK2(PathToPAK2.FileName);
                    foreach (string FileName in FilesToAdd)
                    {
                        NewArchive.AddFile(FileName, FolderToParse.SelectedPath.Length + 1);
                    }
                    PAKReturnType ErrorCode = NewArchive.Save();

                    Cursor.Current = Cursors.Default;
                    if (ErrorCode == PAKReturnType.SUCCESS || ErrorCode == PAKReturnType.SUCCESS_WITH_WARNINGS)
                    {
                        MessageBox.Show("Archive successfully created!", "Finished...", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show(AlienErrors.ErrorMessageBody(ErrorCode), AlienErrors.ErrorMessageTitle(ErrorCode), MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
Example #2
0
        /* Open a PAK archive */
        public PAKReturnType Open(string FilePath)
        {
            //Set PAKHandler to appropriate class depending on input filename
            switch (Path.GetFileName(FilePath).ToUpper())
            {
            case "GLOBAL_TEXTURES.ALL.PAK":
            case "LEVEL_TEXTURES.ALL.PAK":
                PAKHandler = new TexturePAK(FilePath);
                Format     = PAKType.PAK_TEXTURES;
                break;

            case "GLOBAL_MODELS.PAK":
            case "LEVEL_MODELS.PAK":
                PAKHandler = new ModelPAK(FilePath);
                Format     = PAKType.PAK_MODELS;
                break;

            case "MATERIAL_MAPPINGS.PAK":
                PAKHandler = new MaterialMapPAK(FilePath);
                Format     = PAKType.PAK_MATERIALMAPS;
                break;

            //case "COMMANDS.PAK":
            //PAKHandler = new CommandsPAK(FilePath);
            //Format = PAKType.PAK_SCRIPTS;
            //break;
            case "LEVEL_SHADERS_DX11.PAK":
            case "BESPOKESHADERS_DX11.PAK":
            case "DEFERREDSHADERS_DX11.PAK":
            case "POSTPROCESSINGSHADERS_DX11.PAK":
            case "REQUIREDSHADERS_DX11.PAK":
                PAKHandler = new ShaderPAK(FilePath);
                Format     = PAKType.PAK_SHADERS;
                break;

            default:
                PAKHandler = new PAK2(FilePath);
                Format     = PAKType.PAK2;
                break;
            }

            //Attempt to load, and if it fails, set format to UNRECOGNISED
            PAKReturnType LoadReturnInfo = PAKHandler.Load();

            switch (LoadReturnInfo)
            {
            case PAKReturnType.SUCCESS_WITH_WARNINGS:
            case PAKReturnType.SUCCESS:
                return(LoadReturnInfo);

            default:
                Format = PAKType.UNRECOGNISED;
                return(LoadReturnInfo);
            }
        }
Example #3
0
        public string ErrorMessageTitle(PAKReturnType ReturnType)
        {
            switch (ReturnType)
            {
            case PAKReturnType.SUCCESS:
            case PAKReturnType.SUCCESS_WITH_WARNINGS:
                return("Process completed...");

            default:
                return("The process encountered an error...");
            }
        }
Example #4
0
        /* Add to a PAK archive */
        public PAKReturnType AddNewFile(string NewFile)
        {
            if (Format != PAKType.PAK2)
            {
                return(PAKReturnType.FAIL_FEATURE_IS_COMING_SOON);
            }                                                                                 //Currently only supported in PAK2
            PAKReturnType AddFilePAK2 = PAKHandler.AddFile(NewFile);

            if (AddFilePAK2 == PAKReturnType.SUCCESS)
            {
                return(PAKHandler.Save());
            }
            return(AddFilePAK2);
        }
Example #5
0
        /* Remove from a PAK archive */
        public PAKReturnType RemoveFile(string FileName)
        {
            if (Format != PAKType.PAK2)
            {
                return(PAKReturnType.FAIL_FEATURE_IS_COMING_SOON);
            }                                                                                 //Currently only supported in PAK2
            PAKReturnType DeleteFilePAK2 = PAKHandler.DeleteFile(FileName);

            if (DeleteFilePAK2 == PAKReturnType.SUCCESS)
            {
                return(PAKHandler.Save());
            }
            return(DeleteFilePAK2);
        }
Example #6
0
        /* Import to a PAK archive */
        public PAKReturnType ImportFile(string FileName, string ImportPath)
        {
            //Not all formats currently support the full Save() method functionality.
            if (Format == PAKType.PAK2 || Format == PAKType.PAK_MATERIALMAPS)
            {
                PAKReturnType ReplaceFileReturnCode = PAKHandler.ReplaceFile(ImportPath, FileName);
                if (ReplaceFileReturnCode == PAKReturnType.SUCCESS)
                {
                    return(PAKHandler.Save());
                }
                return(ReplaceFileReturnCode);
            }

            return(PAKHandler.ReplaceFile(ImportPath, FileName));
        }
Example #7
0
        /* Export all files from the current archive */
        private void exportAllFilesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Load all file names currently in the UI
            if (AlienPAKs[0].Format == PAKType.UNRECOGNISED)
            {
                MessageBox.Show("No files to export!\nPlease load a PAK archive.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            List <string> AllFiles = AlienPAKs[0].Parse();

            Cursor.Current = Cursors.WaitCursor;

            //Select the folder to dump to
            FolderBrowserDialog FolderToExportTo = new FolderBrowserDialog();

            if (FolderToExportTo.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //Go through all filenames and request an export
            int SuccessCount = 0;

            for (int i = 0; i < AllFiles.Count; i++)
            {
                string ExportPath = FolderToExportTo.SelectedPath + "\\" + AllFiles[i];
                Directory.CreateDirectory(ExportPath.Substring(0, ExportPath.Length - Path.GetFileName(ExportPath).Length));
                PAKReturnType ErrorCode = AlienPAKs[0].ExportFile(AllFiles[i], ExportPath);
                if (ErrorCode == PAKReturnType.SUCCESS || ErrorCode == PAKReturnType.SUCCESS_WITH_WARNINGS)
                {
                    SuccessCount++;
                }
            }

            //Complete!
            Cursor.Current = Cursors.Default;
            if (SuccessCount == AllFiles.Count)
            {
                MessageBox.Show("Successfully exported all files from this PAK!", "Export complete.", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("Export process complete, but " + (AllFiles.Count - SuccessCount) + " files encountered errors.\nPerhaps try a directory with a shorter filepath, or check write access.", "Export complete, with warnings.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Example #8
0
        public string ErrorMessageBody(PAKReturnType ReturnType)
        {
            switch (ReturnType)
            {
            case PAKReturnType.FAIL_ARCHIVE_IS_NOT_EXCPETED_TYPE:
                //This error should be fixed soon once everything has moved to the new class system.
                //Archives can be loaded and tested to see what format they are, without relying on filename.
                return("The loaded archive was not of an expected type.\nPlease check the name of the archive file.");

            case PAKReturnType.FAIL_COULD_NOT_ACCESS_FILE:
                //General file I/O issue - the game is probably open.
                return("Failed to load the requested file.\nIs Alien: Isolation open?");

            case PAKReturnType.FAIL_FEATURE_IS_COMING_SOON:
                //The requested feature is a WIP and not ready to ship yet.
                return("This functionality is coming soon!");

            case PAKReturnType.FAIL_GENERAL_LOGIC_ERROR:
                //General logic issue, the request could not be performed as expected.
                return("The requested action was unable to be performed.\nIf this is incorrect, please open an issue on GitHub.");

            case PAKReturnType.FAIL_REQUEST_IS_UNSUPPORTED:
                //The request is unsupported - likely a V1/V2 texture issue.
                return("The requested action is unsupported in the current context.\nIf this is incorrect, please open an issue on GitHub.");

            case PAKReturnType.FAIL_TRIED_TO_LOAD_VIRTUAL_ARCHIVE:
                //Tried to load a virtual archive that doesn't exist in the filesystem.
                //Don't think this error should ever be shown to the user really, as it would be an underlying logic issue.
                return("Tried to load an archive which doesn't exist!\nThe archive is likely virtual - this is a logic error!\nPlease log this issue to GitHub.");

            case PAKReturnType.FAIL_UNKNOWN:
                //General unknown error.
                return("The requested action failed for an unknown reason.\nPlease log this to AlienPAK's GitHub issues.");

            case PAKReturnType.SUCCESS:
                //General success.
                return("Process complete!");

            case PAKReturnType.SUCCESS_WITH_WARNINGS:
                //General success with warnings.
                return("Process complete.");
            }
            return("An unknown error occured.\nPlease log this to AlienPAK's GitHub issues!");
        }
Example #9
0
        /* Add file to the loaded archive */
        private void AddFileToArchive_Click(object sender, EventArgs e)
        {
            /* This can only happen for UI files, so for OpenCAGE I'm forcing AlienPAKs[0] - might need changing for other PAKs that gain support */

            //Let the user decide what file to add, then add it
            OpenFileDialog FilePicker = new OpenFileDialog();

            FilePicker.Filter = "Any File|*.*";
            if (FilePicker.ShowDialog() == DialogResult.OK)
            {
                Cursor.Current = Cursors.WaitCursor;
                PAKReturnType ResponseCode = AlienPAKs[0].AddNewFile(FilePicker.FileName);
                MessageBox.Show(AlienErrors.ErrorMessageBody(ResponseCode), AlienErrors.ErrorMessageTitle(ResponseCode), MessageBoxButtons.OK, MessageBoxIcon.Information);
                Cursor.Current = Cursors.Default;
            }
            //This is an expensive call for any PAK except PAK2, as it uses the new system.
            //We only can call with PAK2 here so it's fine, but worth noting.
            treeHelper.UpdateFileTree(AlienPAKs[0].Parse());
            UpdateSelectedFilePreview();
        }
Example #10
0
        /* Temp function to get a file as a byte array */
        private byte[] GetFileAsBytes(string FileName)
        {
            PAKReturnType ResponseCode = PAKReturnType.FAIL_UNKNOWN;

            foreach (PAK thisPAK in AlienPAKs)
            {
                ResponseCode = thisPAK.ExportFile(FileName, "temp"); //Should really be able to pull from PAK as bytes
                if (ResponseCode == PAKReturnType.SUCCESS || ResponseCode == PAKReturnType.SUCCESS_WITH_WARNINGS)
                {
                    break;
                }
            }
            if (!File.Exists("temp"))
            {
                return new byte[] { }
            }
            ;
            byte[] ExportedFile = File.ReadAllBytes("temp");
            File.Delete("temp");
            return(ExportedFile);
        }
Example #11
0
        /* Remove selected file from the archive */
        private void RemoveFileFromArchive_Click(object sender, EventArgs e)
        {
            /* This can only happen for UI files, so for OpenCAGE I'm forcing AlienPAKs[0] - might need changing for other PAKs that gain support */

            if (FileTree.SelectedNode == null || ((TreeItem)FileTree.SelectedNode.Tag).Item_Type != TreeItemType.EXPORTABLE_FILE)
            {
                MessageBox.Show("Please select a file from the list.", "No file selected.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            DialogResult ConfirmRemoval = MessageBox.Show("Are you sure you would like to remove this file?", "About to remove selected file...", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (ConfirmRemoval == DialogResult.Yes)
            {
                Cursor.Current = Cursors.WaitCursor;
                PAKReturnType ResponseCode = AlienPAKs[0].RemoveFile(((TreeItem)FileTree.SelectedNode.Tag).String_Value);
                MessageBox.Show(AlienErrors.ErrorMessageBody(ResponseCode), AlienErrors.ErrorMessageTitle(ResponseCode), MessageBoxButtons.OK, MessageBoxIcon.Information);
                Cursor.Current = Cursors.Default;
            }
            //This is an expensive call for any PAK except PAK2, as it uses the new system.
            //We only can call with PAK2 here so it's fine, but worth noting.
            treeHelper.UpdateFileTree(AlienPAKs[0].Parse());
            UpdateSelectedFilePreview();
        }
Example #12
0
        /* Export the selected PAK entry as a standalone file */
        private void ExportSelectedFile()
        {
            if (FileTree.SelectedNode == null || ((TreeItem)FileTree.SelectedNode.Tag).Item_Type != TreeItemType.EXPORTABLE_FILE)
            {
                MessageBox.Show("Please select a file from the list.", "No file selected.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            //If export file is DDS, check first to see if we can export as WIC format
            string filter = "Exported File|*" + Path.GetExtension(FileTree.SelectedNode.Text);

            byte[] ImageFile = new byte[] { };
            if (Path.GetExtension(FileTree.SelectedNode.Text).ToUpper() == ".DDS")
            {
                ImageFile = GetFileAsBytes(((TreeItem)FileTree.SelectedNode.Tag).String_Value);
                try
                {
                    TexHelper.Instance.LoadFromDDSMemory(Marshal.UnsafeAddrOfPinnedArrayElement(ImageFile, 0), ImageFile.Length, DDS_FLAGS.NONE);
                    filter = "PNG Image|*.png|DDS Image|*.dds"; //Can export as WIC
                }
                catch
                {
                    ImageFile = new byte[] { };
                }
            }

            //Remove extension from output filename
            string filename = Path.GetFileName(FileTree.SelectedNode.Text);

            while (Path.GetExtension(filename).Length != 0)
            {
                filename = filename.Substring(0, filename.Length - Path.GetExtension(filename).Length);
            }

            //Let the user decide where to save, then save
            SaveFileDialog FilePicker = new SaveFileDialog();

            FilePicker.Filter   = filter;
            FilePicker.FileName = filename;
            if (FilePicker.ShowDialog() == DialogResult.OK)
            {
                Cursor.Current = Cursors.WaitCursor;
                //Special export for DDS conversion
                if (ImageFile.Length > 0 && FilePicker.FilterIndex == 1) //Index 1 == PNG, if ImageFile hasn't been cleared (we can export as WIC)
                {
                    try
                    {
                        ScratchImage img      = TexHelper.Instance.LoadFromDDSMemory(Marshal.UnsafeAddrOfPinnedArrayElement(ImageFile, 0), ImageFile.Length, DDS_FLAGS.NONE);
                        ScratchImage imgDecom = img.Decompress(DXGI_FORMAT.UNKNOWN);
                        imgDecom.SaveToWICFile(0, WIC_FLAGS.NONE, TexHelper.Instance.GetWICCodec(WICCodecs.PNG), FilePicker.FileName);
                        MessageBox.Show(AlienErrors.ErrorMessageBody(PAKReturnType.SUCCESS), AlienErrors.ErrorMessageTitle(PAKReturnType.SUCCESS), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    catch
                    {
                        MessageBox.Show("Failed to export as PNG!\nPlease try again as DDS.", AlienErrors.ErrorMessageTitle(PAKReturnType.FAIL_UNKNOWN), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                //Regular export
                else
                {
                    PAKReturnType ResponseCode = PAKReturnType.FAIL_UNKNOWN;
                    foreach (PAK thisPAK in AlienPAKs)
                    {
                        ResponseCode = thisPAK.ExportFile(((TreeItem)FileTree.SelectedNode.Tag).String_Value, FilePicker.FileName);
                        if (ResponseCode == PAKReturnType.SUCCESS || ResponseCode == PAKReturnType.SUCCESS_WITH_WARNINGS)
                        {
                            break;
                        }
                    }
                    MessageBox.Show(AlienErrors.ErrorMessageBody(ResponseCode), AlienErrors.ErrorMessageTitle(ResponseCode), MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                Cursor.Current = Cursors.Default;
            }
        }