Example #1
0
        public static void Open(LibertyV window, string filename)
        {
            RPF7File file   = null;
            Stream   stream = null;

            try
            {
                new ProgressWindow("Open", progress =>
                {
                    progress.SetMessage("Loading..");
                    progress.SetProgress(-1);
                    stream = File.OpenRead(filename);
                    file   = new RPF7File(stream, Path.GetFileName(filename), filename);
                }).Run();
            }
            catch (RPFParsingException ex)
            {
                MessageBox.Show(ex.Message, "Failed to load RPF", MessageBoxButtons.OK, MessageBoxIcon.Error);
                if (stream != null)
                {
                    stream.Close();
                }
                return;
            }
            window.LoadRPF(file);
        }
Example #2
0
        public LibertyV(RPF7File rpf = null, string tempOutputFile = null)
        {
            InitializeComponent();

            TempOutputFile = tempOutputFile;

            filesList.Columns.Add("Name", 300);
            filesList.Columns.Add("Size", 100);
            filesList.Columns.Add("Resource Type", 100);

            Comparison <TreeNode> treeSorter = (x, y) => x.Name.CompareTo(y.Name);

            filesTree.TreeViewNodeSorter = new NodeSorter();

            if (rpf != null)
            {
                this.LoadRPF(rpf);
            }

            if (tempOutputFile != null)
            {
                // limit the gui,, TODO: better
                fileOpenButton.Enabled = false;
            }

            // Load menu
            foreach (Operations.IMenuItem <LibertyV> item in Operations.Operations.MenuStrip)
            {
                // All the other items are ignored
                if (item is Operations.SubMenuItem <LibertyV> )
                {
                    menuStrip.Items.Add((item as Operations.SubMenuItem <LibertyV>).GetContextMenuItemUpdatedOnOpening(this));
                }
            }
        }
Example #3
0
        public void LoadRPF(RPF7File rpf, bool updateGui = false)
        {
            // Close file
            CloseRPF(!updateGui);
            this.File = rpf;
            this.Text = String.Format("Liberty V - {0}", this.File.Filename);

            this.saveAsButton.Enabled = true;
            this.saveButton.Enabled   = true;

            if (updateGui)
            {
                UpdateGUIEntries();
            }
            else
            {
                exportAllButton.Enabled = true;
                UpdateExportSelectButton();
                filesTree.Nodes.Clear();
                filesList.Items.Clear();

                TreeNode root = GetTreeNodes(this.File.Root as DirectoryEntry);
                root.Text = rpf.Filename;
                filesTree.Nodes.Add(root);

                filesTree.SelectedNode = root;
                UpdateExportSelectButton();
                UpdateFilesList();
            }
        }
Example #4
0
 private void LibertyV_FormClosed(object sender, FormClosedEventArgs e)
 {
     if (this.File != null)
     {
         this.File.Close();
         this.File = null;
     }
 }
Example #5
0
        public GTANETRPF7(RPF7File rpf = null)
        {
            InitializeComponent();

            filesList.Columns.Add("Name", 300);
            filesList.Columns.Add("Size", 100);
            filesList.Columns.Add("Resource Type", 100);

            Comparison <TreeNode> treeSorter = (x, y) => x.Name.CompareTo(y.Name);

            filesTree.TreeViewNodeSorter = new NodeSorter();

            if (rpf != null)
            {
                this.LoadRPF(rpf);
            }
        }
Example #6
0
        public void CloseRPF(bool clearGui = true)
        {
            if (this.File != null)
            {
                // Close last file
                this.File.Close();
                this.File = null;
            }
            this.saveAsButton.Enabled = false;
            this.saveButton.Enabled   = false;

            if (clearGui)
            {
                filesTree.Nodes.Clear();
                filesList.Items.Clear();
                this.Text = String.Format("Liberty V - Grand Theft Auto V RPF Viewer");
            }
        }
Example #7
0
        private void LoadRPF(RPF7File rpf)
        {
            this.File = rpf;

            exportAllButton.Enabled = true;
            UpdateExportSelectButton();
            filesTree.Nodes.Clear();
            filesList.Items.Clear();

            TreeNode root = GetTreeNodes(this.File.Root as DirectoryEntry);

            root.Text = rpf.Filename;
            filesTree.Nodes.Add(root);

            filesTree.SelectedNode = root;
            UpdateExportSelectButton();
            UpdateFilesList();
        }
Example #8
0
        public static Entry CreateFromHeader(Structs.RPF7EntryInfoTemplate info, RPF7File file, MemoryStream entriesInfo, MemoryStream filenames)
        {
            bool isResource     = info.Field1 == 1;
            long offset         = (long)info.Field2;
            int  compressedSize = (int)info.Field3;
            int  filenameOffset = (int)info.Field4;

            filenames.Seek(filenameOffset << file.Info.ShiftNameAccessBy, SeekOrigin.Begin);
            String filename = "";
            // Read null-terminated filename
            int currentChar;

            while ((currentChar = filenames.ReadByte()) != 0)
            {
                if (currentChar == -1)
                {
                    throw new Exception("Unexpected EOF");
                }
                filename += (char)currentChar;
            }

            if (offset == 0x7FFFFF)
            {
                // Is a Directory
                if (isResource)
                {
                    throw new Exception("Invalid type");
                }
                int          subentriesStartIndex = (int)info.Field5;
                int          subentriesCount      = (int)info.Field6;
                List <Entry> entries = new List <Entry>();
                for (int i = 0; i < subentriesCount; ++i)
                {
                    entriesInfo.Seek(0x10 * (i + subentriesStartIndex), SeekOrigin.Begin);
                    entries.Add(Entry.CreateFromHeader(new Structs.RPF7EntryInfoTemplate(entriesInfo), file, entriesInfo, filenames));
                }
                return(new DirectoryEntry(filename, entries));
            }

            offset <<= 9;

            if (isResource)
            {
                if (compressedSize == 0xFFFFFF)
                {
                    throw new Exception("Resource with size -1, not supported");
                }
                uint systemFlag   = info.Field5;
                uint graphicsFlag = info.Field6;
                return(new ResourceEntry(filename, new ResourceStreamCreator(file, offset, compressedSize, systemFlag, graphicsFlag), systemFlag, graphicsFlag));
            }

            // Regular file
            int uncompressedSize = (int)info.Field5;
            int isEncrypted      = (int)info.Field6;

            if (compressedSize == 0)
            {
                // Uncompressed file
                if (isEncrypted != 0)
                {
                    throw new Exception("Unexcepted value");
                }
                return(new RegularFileEntry(filename, new FileStreamCreator(file, offset, uncompressedSize), false));
            }
            else
            {
                // Compressed file
                return(new RegularFileEntry(filename, new CompressedFileStreamCreator(file, offset, compressedSize, uncompressedSize, isEncrypted != 0), true));
            }
        }
Example #9
0
        public static Entry CreateFromHeader(Structs.RPF7EntryInfoTemplate info, RPF7File file, MemoryStream entriesInfo, MemoryStream filenames)
        {
            bool isResource = info.Field1 == 1;
            long offset = (long)info.Field2;
            int compressedSize = (int)info.Field3;
            int filenameOffset = (int)info.Field4;

            filenames.Seek(filenameOffset << file.Info.ShiftNameAccessBy, SeekOrigin.Begin);
            String filename = "";
            // Read null-terminated filename
            int currentChar;
            while ((currentChar = filenames.ReadByte()) != 0)
            {
                if (currentChar == -1)
                {
                    throw new Exception("Unexpected EOF");
                }
                filename += (char)currentChar;
            }

            if (offset == 0x7FFFFF)
            {
                // Is a Directory
                if (isResource)
                {
                    throw new Exception("Invalid type");
                }
                int subentriesStartIndex = (int)info.Field5;
                int subentriesCount = (int)info.Field6;
                List<Entry> entries = new List<Entry>();
                for (int i = 0; i < subentriesCount; ++i)
                {
                    entriesInfo.Seek(0x10 * (i + subentriesStartIndex), SeekOrigin.Begin);
                    entries.Add(Entry.CreateFromHeader(new Structs.RPF7EntryInfoTemplate(entriesInfo), file, entriesInfo, filenames));
                }
                return new DirectoryEntry(filename, entries);
            }

            offset <<= 9;

            if (isResource)
            {
                if (compressedSize == 0xFFFFFF)
                {
                    throw new Exception("Resource with size -1, not supported");
                }
                uint systemFlag = info.Field5;
                uint graphicsFlag = info.Field6;
                return new ResourceEntry(filename, new ResourceStreamCreator(file, offset, compressedSize, systemFlag, graphicsFlag), systemFlag, graphicsFlag);
            }

            // Regular file
            int uncompressedSize = (int)info.Field5;
            int isEncrypted = (int)info.Field6;

            if (compressedSize == 0)
            {
                // Uncompressed file
                if (isEncrypted != 0)
                {
                    throw new Exception("Unexcepted value");
                }
                return new RegularFileEntry(filename, new FileStreamCreator(file, offset, uncompressedSize), false);
            }
            else
            {
                // Compressed file
                return new RegularFileEntry(filename, new CompressedFileStreamCreator(file, offset, compressedSize, uncompressedSize, isEncrypted != 0), true);
            }
        }