Exemple #1
0
        public PacFileHandling(BinaryReader b)
        {
            pacFile = new Pac();
            pacStream = b;
            pacFile.header = ReadHeader();

            PacDirParse dirParse = new PacDirParse(pacStream, pacFile);
            PACHParser pachParse = new PACHParser();
            TextureParser textureParse = new TextureParser();

            if (pacFile.header.id == "PACH")
            {
                //You opened a free floating PACH file~!
                pacStream.BaseStream.Position = 0;
                pacFile.container = pachParse.ReadPACHContainer(pacStream.ReadBytes((int)pacStream.BaseStream.Length));
            }
            else if (pacFile.header.id == "EPK8" || pacFile.header.id == "EPAC")
            {
                pacFile.dir = dirParse.ReadDir().ToArray();
            }
            else
            {
                //probably a texture archive...
                //pacFile.header.id = "Texture Archive";
                pacStream.BaseStream.Position = 0;
                pacFile.textures = textureParse.ReadTextures(pacStream);
            }
        }
Exemple #2
0
        public PacFileHandling(BinaryReader b)
        {
            pacFile        = new Pac();
            pacStream      = b;
            pacFile.header = ReadHeader();

            PacDirParse   dirParse     = new PacDirParse(pacStream, pacFile);
            PACHParser    pachParse    = new PACHParser();
            TextureParser textureParse = new TextureParser();

            if (pacFile.header.id == "PACH")
            {
                //You opened a free floating PACH file~!
                pacStream.BaseStream.Position = 0;
                pacFile.container             = pachParse.ReadPACHContainer(pacStream.ReadBytes((int)pacStream.BaseStream.Length));
            }
            else if (pacFile.header.id == "EPK8" || pacFile.header.id == "EPAC")
            {
                pacFile.dir = dirParse.ReadDir().ToArray();
            }
            else
            {
                //probably a texture archive...
                //pacFile.header.id = "Texture Archive";
                pacStream.BaseStream.Position = 0;
                pacFile.textures = textureParse.ReadTextures(pacStream);
            }
        }
Exemple #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);
                }
            }
        }