Example #1
0
        public void ReadFile(byte[] bytes, int version)
        {
            int Length = 276;

            if (version == 131075)
            {
                Length = 288;
            }
            if (bytes.Length < Length)
            {
                bytes = Zlib.Decompress(bytes, Length);
            }
            BinaryReader br = new BinaryReader(new MemoryStream(bytes));

            Path = Encoding.GetEncoding(936).GetString(br.ReadBytes(260)).Split(new string[] { "\0" }, StringSplitOptions.RemoveEmptyEntries)[0].Replace("/", "\\");
            if (version == 131075)
            {
                v3p1   = br.ReadInt32();
                Offset = br.ReadInt64();
            }
            else
            {
                Offset = br.ReadUInt32();
            }
            Size           = br.ReadInt32();
            CompressedSize = br.ReadInt32();
            if (version == 131075)
            {
                v3p2 = br.ReadInt32();
            }
            unk = br.ReadInt32();
            br.Close();
        }
Example #2
0
        public byte[] WriteFile(int CompressionLevel, int version)
        {
            int Length = 276;

            if (version == 131075)
            {
                Length = 288;
            }
            byte[]       buffer = new byte[Length];
            MemoryStream msb    = new MemoryStream(buffer);
            BinaryWriter bw     = new BinaryWriter(msb);

            bw.Write(Encoding.GetEncoding("GB2312").GetBytes(Path.Replace("/", "\\")));
            bw.BaseStream.Seek(260, SeekOrigin.Begin);
            if (version == 131075)
            {
                bw.Write(v3p1);
                bw.Write(Offset);
            }
            else
            {
                bw.Write((uint)Offset);
            }
            bw.Write(Size);
            bw.Write(CompressedSize);
            if (version == 131075)
            {
                bw.Write(v3p2);
            }
            bw.Write(unk);
            bw.BaseStream.Seek(0, SeekOrigin.Begin);
            bw.Close();
            byte[] compressed = Zlib.Compress(buffer, CompressionLevel);
            return(compressed.Length < Length ? compressed : buffer);
        }
Example #3
0
        public static MemoryStream GetFile(FileInfo[] FileTable, string PackagePath, string GameMode, string File)
        {
            Package package = new Package(PackagePath, Keys.SetKeys(GameMode));

            for (int i = 0; i < FileTable.Length; i++)
            {
                if (File.ToLower() == FileTable[i].Path.ToLower())
                {
                    package.Seek(FileTable[i].Offset, SeekOrigin.Begin);
                    byte[] file = package.ReadBytes(FileTable[i].CompressedSize);
                    if (FileTable[i].CompressedSize < FileTable[i].Size)
                    {
                        package.Dispose();
                        return(new MemoryStream(Zlib.Decompress(file, FileTable[i].Size)));
                    }
                    else
                    {
                        package.Dispose();
                        return(new MemoryStream(file));
                    }
                }
            }
            package.Dispose();
            return(new MemoryStream());
        }