예제 #1
0
        public C2File ReadFile(bool justMeta = false)
        {
            C2File file = new C2File();
            file.Position = reader.BaseStream.Position;
            Int32 sign = reader.ReadInt32();

            if (sign != SIGN)
                throw new Exception("Sign isn't right.");


            file.VER = reader.ReadInt16();
            file.FLAG = reader.ReadInt16();
            file.METHOD = reader.ReadInt16();
            file.TIME = reader.ReadInt16();
            file.DATE = reader.ReadInt16();

            file.CRC32 = reader.ReadInt32();
            file.ZSIZE = reader.ReadInt32();
            file.SIZE = reader.ReadInt32();
            file.NSIZE = reader.ReadInt32();

            file.NAME = new String(reader.ReadChars(file.NSIZE));

            if (!justMeta)
            { 
                file.Data = reader.ReadBytes(file.ZSIZE);

                if (file.METHOD != 0)
                    file.InflateData();
            }
            else
            {
                reader.BaseStream.Position += file.ZSIZE;
            }

            return file;
        }
예제 #2
0
        public void ReplaceFileContent(C2File file)
        {
            if (file.VER < 0)
                throw new Exception("Improper version");

            //Save our position
            Int64 tempPos = reader.BaseStream.Position;
            reader.BaseStream.Seek(0, SeekOrigin.Begin);

            //Split the stream
            List<Byte> before = new List<byte>(reader.ReadBytes((int)file.Position));
            C2File originalFile = ReadFile();
            List<Byte> after = new List<byte>(reader.ReadBytes((int)(reader.BaseStream.Length - reader.BaseStream.Position)));

            //Get the bytes that we're putting back in
            file.UpdateCRC32();
            file.DeflateData();
            byte[] outBytes = file.ToBytes();
            file.InflateData();

            //Write to a file
            String sFile = @"E:\Program Files (x86)\CABAL2 (US)\game\c2localize_us_ts.pak";
            FileStream f = File.Create(sFile + "2");
            f.Write(before.ToArray(), 0, before.Count);
            f.Write(outBytes, 0, outBytes.Length);
            f.Write(after.ToArray(), 0, after.Count);
            f.Close();

            //Clear stuff and restore position
            before.Clear();
            after.Clear();

            reader.BaseStream.Seek(tempPos, SeekOrigin.Begin);
        }