Ejemplo n.º 1
0
        private void option1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem item in listView1.SelectedItems)
            {
                string name = Path.GetDirectoryName(file) + "\\" + item.SubItems[0].Text;

                if (item.Tag.GetType().Equals(typeof(TextureArchive)))
                {
                    TextureArchive texfile = (TextureArchive)item.Tag;
                    efile.ExtractFile(texfile.stream, name);
                }
                if (item.Tag.GetType().Equals(typeof(PacFile)))
                {
                    PacFile pacfile = (PacFile)item.Tag;
                    efile.ExtractFile(pacfile.stream, name);
                }
                if (item.Tag.GetType().Equals(typeof(PACHFile)))
                {
                    PACHFile pachfile = (PACHFile)item.Tag;
                    efile.ExtractFile(pachfile.stream, name);
                }
                if (item.Tag.GetType().Equals(typeof(PACH)))
                {
                    PACH pachcontainer = (PACH)item.Tag;
                    efile.ExtractFile(pachcontainer.PACHFiles[0].stream, name);
                }
            }
        }
Ejemplo n.º 2
0
        public PACH ReadPACHContainer(byte[] file)
        {
            using (MemoryStream pachStream = new MemoryStream(file))
            {
                using (BinaryReader pachReader = new BinaryReader(pachStream))
                {
                    var Container = new PACH();
                    Container.id = new string(pachReader.ReadChars(4));

                    if (Container.id != "PACH")
                    {
                        return(Container); //Thanks a lot createmode.pac....
                    }

                    Container.nfiles = (int)pachReader.ReadUInt32();


                    //Read the file meta data
                    Container.PACHFiles = new PACHFile[Container.nfiles];
                    for (var i = 0; i < Container.nfiles; i++)
                    {
                        Container.PACHFiles[i] = ReadPACHheader(pachReader);
                    }


                    //Start of data. Meta data offsets start here
                    var pos = pachReader.BaseStream.Position; //offsets are based on this.
                    for (var j = 0; j < Container.nfiles; j++)
                    {
                        pachReader.BaseStream.Position = Container.PACHFiles[j].offset + pos;

                        Container.PACHFiles[j].stream = pachReader.ReadBytes(Container.PACHFiles[j].size);

                        byte[] headerByteArray = new byte[4]; Array.Copy(Container.PACHFiles[j].stream, 0, headerByteArray, 0, 4);
                        var    header          = System.Text.Encoding.UTF8.GetString(headerByteArray);
                        if (header == "PACH")
                        {
                            Container.PACHFiles[j].SubContainer = ReadPACHContainer(Container.PACHFiles[j].stream);
                        }
                        //Let's go ahead and decompress here.
                        if (header == "ZLIB" || header == "BPE ")
                        {
                            Container.PACHFiles[j].stream = decompressor.Decompress(Container.PACHFiles[j].stream, header);
                            Container.PACHFiles[j].size   = Container.PACHFiles[j].stream.Length;

                            //Recheck it.
                            headerByteArray = new byte[4];
                            Array.Copy(Container.PACHFiles[j].stream, 0, headerByteArray, 0, 4);
                            header = System.Text.Encoding.UTF8.GetString(headerByteArray);
                            if (header == "PACH")
                            {
                                Container.PACHFiles[j].SubContainer = ReadPACHContainer(Container.PACHFiles[j].stream);
                            }
                            else
                            {
                                //Check for textures, the first dds extension starts at 32.
                                if (Container.PACHFiles[j].stream.Length >= 32)
                                {
                                    headerByteArray = new byte[4];
                                    Array.Copy(Container.PACHFiles[j].stream, 32, headerByteArray, 0, 4);
                                    header = System.Text.Encoding.UTF8.GetString(headerByteArray);
                                    if (header == "dds\0")
                                    {
                                        using (MemoryStream texStream = new MemoryStream(Container.PACHFiles[j].stream))
                                        {
                                            using (BinaryReader texReader = new BinaryReader(texStream))
                                            {
                                                Container.PACHFiles[j].TexContainer = textureParse.ReadTextures(texReader);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }

                    return(Container);
                }
            }
        }
Ejemplo n.º 3
0
        public PACH ReadPACHContainer(byte[] file)
        {
            using (MemoryStream pachStream = new MemoryStream(file))
            {
                using (BinaryReader pachReader = new BinaryReader(pachStream))
                {
                    var Container = new PACH();
                    Container.id = new string(pachReader.ReadChars(4));

                    if (Container.id != "PACH")
                    {
                        return Container; //Thanks a lot createmode.pac....
                    }

                    Container.nfiles = (int)pachReader.ReadUInt32();

                    //Read the file meta data
                    Container.PACHFiles = new PACHFile[Container.nfiles];
                    for (var i = 0; i < Container.nfiles; i++)
                    {
                        Container.PACHFiles[i] = ReadPACHheader(pachReader);
                    }

                    //Start of data. Meta data offsets start here
                    var pos = pachReader.BaseStream.Position; //offsets are based on this.
                    for (var j = 0; j < Container.nfiles; j++)
                    {
                        pachReader.BaseStream.Position = Container.PACHFiles[j].offset + pos;

                        Container.PACHFiles[j].stream = pachReader.ReadBytes(Container.PACHFiles[j].size);

                        byte[] headerByteArray = new byte[4]; Array.Copy(Container.PACHFiles[j].stream, 0, headerByteArray, 0, 4);
                        var header = System.Text.Encoding.UTF8.GetString(headerByteArray);
                        if (header == "PACH")
                        {
                            Container.PACHFiles[j].SubContainer = ReadPACHContainer(Container.PACHFiles[j].stream);
                        }
                        //Let's go ahead and decompress here.
                        if (header == "ZLIB" || header == "BPE ")
                        {
                            Container.PACHFiles[j].stream = decompressor.Decompress(Container.PACHFiles[j].stream, header);
                            Container.PACHFiles[j].size = Container.PACHFiles[j].stream.Length;

                            //Recheck it.
                            headerByteArray = new byte[4];
                            Array.Copy(Container.PACHFiles[j].stream, 0, headerByteArray, 0, 4);
                            header = System.Text.Encoding.UTF8.GetString(headerByteArray);
                            if (header == "PACH")
                            {
                                Container.PACHFiles[j].SubContainer = ReadPACHContainer(Container.PACHFiles[j].stream);
                            }
                            else
                            {
                                //Check for textures, the first dds extension starts at 32.
                                if (Container.PACHFiles[j].stream.Length >= 32)
                                {
                                    headerByteArray = new byte[4];
                                    Array.Copy(Container.PACHFiles[j].stream, 32, headerByteArray, 0, 4);
                                    header = System.Text.Encoding.UTF8.GetString(headerByteArray);
                                    if (header == "dds\0")
                                    {
                                        using (MemoryStream texStream = new MemoryStream(Container.PACHFiles[j].stream))
                                        {
                                            using (BinaryReader texReader = new BinaryReader(texStream))
                                            {
                                                Container.PACHFiles[j].TexContainer = textureParse.ReadTextures(texReader);
                                            }
                                        }
                                    }
                                }

                            }
                        }
                    }

                    return Container;
                }
            }
        }
Ejemplo n.º 4
0
        //Check the node type and populate the listview based on it.
        void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            TreeNode newSelected = e.Node;

            listView1.Items.Clear();
            ListViewItem item = null;

            ListViewItem.ListViewSubItem[] subItems;


            //right click = extract all menu.
            if (e.Button == MouseButtons.Right)
            {
                if (newSelected.Bounds.Contains(e.Location) == true)
                {
                    contextMenuStrip2.Show(Cursor.Position);
                }
            }

            if (newSelected.Tag != null)
            {
                if (newSelected.Tag.GetType().Equals(typeof(TextureArchive[])))
                {
                    //TextureArchive textures
                    TextureArchive[] textures = (TextureArchive[])newSelected.Tag;
                    foreach (var texture in textures)
                    {
                        var file = texture.alignedstring.Replace("\0", string.Empty).Trim() + "." + texture.extension.Replace("\0", string.Empty).Trim();

                        item     = new ListViewItem(file, 2);
                        item.Tag = texture;
                        subItems = new ListViewItem.ListViewSubItem[]
                        {
                            new ListViewItem.ListViewSubItem(item, texture.extension)
                            , new ListViewItem.ListViewSubItem(item, texture.size.ToString())
                        };
                        item.SubItems.AddRange(subItems);
                        listView1.Items.Add(item);
                    }
                }
                else if (newSelected.Tag.GetType().Equals(typeof(PacDir)))
                {
                    PacDir nodeDirInfo = (PacDir)newSelected.Tag;

                    if (nodeDirInfo.PacFiles != null)
                    {
                        foreach (var file in nodeDirInfo.PacFiles)
                        {
                            item     = new ListViewItem(file.id, 2);
                            item.Tag = file;
                            subItems = new ListViewItem.ListViewSubItem[]
                            {
                                new ListViewItem.ListViewSubItem(item, file.PACHContainer.id.ToString())  //Header of the contained file
                                , new ListViewItem.ListViewSubItem(item, file.size.ToString())
                            };
                            item.SubItems.AddRange(subItems);
                            listView1.Items.Add(item);
                        }
                    }
                }
                else if (newSelected.Tag.GetType().Equals(typeof(PACH)))
                {
                    PACH nodeDirInfo = (PACH)newSelected.Tag;

                    if (nodeDirInfo.PACHFiles != null)
                    {
                        foreach (var file in nodeDirInfo.PACHFiles)
                        {
                            var subFileText = new byte[4];
                            Array.Copy(file.stream, 0, subFileText, 0, 4);
                            var name = System.Text.Encoding.UTF8.GetString(subFileText);

                            item     = new ListViewItem(file.id, 1);
                            item.Tag = file;
                            subItems = new ListViewItem.ListViewSubItem[]
                            {
                                new ListViewItem.ListViewSubItem(item, name) //Type
                                , new ListViewItem.ListViewSubItem(item, file.size.ToString())
                            };
                            item.SubItems.AddRange(subItems);
                            listView1.Items.Add(item);
                        }
                    }
                }
                else if (newSelected.Tag.GetType().Equals(typeof(PACHFile)))
                {
                    PACHFile nodeDirInfo = (PACHFile)newSelected.Tag;
                    if (nodeDirInfo.SubContainer != null) //more pach files...
                    {
                        foreach (PACHFile subFile in nodeDirInfo.SubContainer.PACHFiles)
                        {
                            var subFileText = new byte[4];
                            Array.Copy(subFile.stream, 0, subFileText, 0, 4);
                            var name = System.Text.Encoding.UTF8.GetString(subFileText);

                            item     = new ListViewItem(subFile.id, 1);
                            item.Tag = subFile;
                            subItems = new ListViewItem.ListViewSubItem[]
                            {
                                new ListViewItem.ListViewSubItem(item, name)  //Type
                                , new ListViewItem.ListViewSubItem(item, subFile.size.ToString())
                            };
                            item.SubItems.AddRange(subItems);
                            listView1.Items.Add(item);
                        }
                    }
                    else if (nodeDirInfo.TexContainer != null) // Texture files
                    {
                        foreach (TextureArchive subFile in nodeDirInfo.TexContainer)
                        {
                            var file = subFile.alignedstring.Replace("\0", string.Empty).Trim() + "." + subFile.extension.Replace("\0", string.Empty).Trim();

                            item     = new ListViewItem(file, 2);
                            item.Tag = subFile;
                            subItems = new ListViewItem.ListViewSubItem[]
                            {
                                new ListViewItem.ListViewSubItem(item, subFile.extension)  //Header of the contained file
                                , new ListViewItem.ListViewSubItem(item, subFile.size.ToString())
                            };
                            item.SubItems.AddRange(subItems);
                            listView1.Items.Add(item);
                        }
                    }
                    else //Everything else
                    {
                        var subFileText = new byte[4];
                        Array.Copy(nodeDirInfo.stream, 0, subFileText, 0, 4);
                        var name = System.Text.Encoding.UTF8.GetString(subFileText);

                        item     = new ListViewItem(nodeDirInfo.id, 1);
                        item.Tag = nodeDirInfo;
                        subItems = new ListViewItem.ListViewSubItem[]
                        {
                            new ListViewItem.ListViewSubItem(item, name) //Type
                            , new ListViewItem.ListViewSubItem(item, nodeDirInfo.size.ToString())
                        };
                        item.SubItems.AddRange(subItems);
                        listView1.Items.Add(item);
                    }
                }
                else if (newSelected.Tag.GetType().Equals(typeof(PacFile)))
                {
                    PacFile nodeDirInfo = (PacFile)newSelected.Tag;

                    if (nodeDirInfo.PACHContainer.PACHFiles != null)
                    {
                        foreach (var file in nodeDirInfo.PACHContainer.PACHFiles)
                        {
                            var subFileText = new byte[4];
                            Array.Copy(file.stream, 0, subFileText, 0, 4);
                            var name = System.Text.Encoding.UTF8.GetString(subFileText);

                            item     = new ListViewItem(file.id, 1);
                            item.Tag = file;
                            subItems = new ListViewItem.ListViewSubItem[]
                            {
                                new ListViewItem.ListViewSubItem(item, name) //Type
                                , new ListViewItem.ListViewSubItem(item, file.size.ToString())
                            };
                            item.SubItems.AddRange(subItems);
                            listView1.Items.Add(item);
                        }
                    }
                }
            }
            listView1.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }