Exemplo n.º 1
0
        /*
         * Reads pack header from the given reader.
         */
        public static PFHeader ReadHeader(BinaryReader reader)
        {
            PFHeader header;
            string   packIdentifier = new string (reader.ReadChars(4));

            header = new PFHeader(packIdentifier);
            int packType = reader.ReadInt32();

            header.PrecedenceByte = (byte)packType;
            // header.Type = (PackType)packType;
            header.Version = reader.ReadInt32();
            int replacedPackFilenameLength = reader.ReadInt32();

            reader.BaseStream.Seek(0x10L, SeekOrigin.Begin);
            header.FileCount = reader.ReadUInt32();
            UInt32 indexSize = reader.ReadUInt32();

            header.DataStart = header.Length + indexSize;

            if (header.PackIdentifier == "PFH4")
            {
                header.Unknown = reader.ReadUInt32();
            }

            // go to correct position
            reader.BaseStream.Seek(header.Length, SeekOrigin.Begin);
            for (int i = 0; i < header.Version; i++)
            {
                header.ReplacedPackFileNames.Add(IOFunctions.ReadZeroTerminatedAscii(reader));
            }
            header.DataStart += replacedPackFilenameLength;
            return(header);
        }
Exemplo n.º 2
0
        /*
         * Decode pack file at the given path.
         */
        public PackFile Open(string packFullPath)
        {
            PackFile file;
            long     sizes = 0;

            using (var reader = new BinaryReader(new FileStream(packFullPath, FileMode.Open), Encoding.ASCII))
            {
                PFHeader header = ReadHeader(reader);
                file = new PackFile(packFullPath, header);
                OnHeaderLoaded(header);

                long offset = file.Header.DataStart;
                for (int i = 0; i < file.Header.FileCount; i++)
                {
                    uint size = reader.ReadUInt32();
                    sizes += size;
                    if (file.Header.HasAdditionalInfo)
                    {
                        header.AdditionalInfo = reader.ReadInt64();
                    }
                    string packedFileName = IOFunctions.ReadZeroTerminatedAscii(reader);
                    // this is easier because we can use the Path methods
                    // under both Windows and Unix
                    packedFileName = packedFileName.Replace('\\', Path.DirectorySeparatorChar);

                    PackedFile packed = new PackedFile(file.Filepath, packedFileName, offset, size);
                    file.Add(packed);
                    offset += size;
                    this.OnPackedFileLoaded(packed);
                }
            }
            this.OnFinishedLoading(file);
            file.IsModified = false;
            return(file);
        }
Exemplo n.º 3
0
 public override void Encode(BinaryWriter writer)
 {
     writer.Write(Value.Length > 0);
     if (Value.Length > 0)
     {
         IOFunctions.WriteCAString(writer, Value.Trim(), stringEncoding);
     }
 }
Exemplo n.º 4
0
 public static void WriteHeader(BinaryWriter writer, DBFileHeader header)
 {
     if (header.GUID != "")
     {
         writer.Write(GUID_MARKER);
         IOFunctions.WriteCAString(writer, header.GUID, Encoding.Unicode);
     }
     if (header.Version != 0)
     {
         writer.Write(VERSION_MARKER);
         writer.Write(header.Version);
     }
     writer.Write((byte)1);
     writer.Write(header.EntryCount);
 }
Exemplo n.º 5
0
        public override void Decode(BinaryReader reader)
        {
            string result = "";
            byte   b      = reader.ReadByte();

            if (b == 1)
            {
                result         = IOFunctions.ReadCAString(reader, stringEncoding);
                readLengthZero = result.Length == 0;
            }
            else if (b != 0)
            {
                throw new InvalidDataException(string.Format("- invalid - ({0:x2})", b));
            }
            Value = result;
        }
Exemplo n.º 6
0
        public static DBFileHeader readHeader(BinaryReader reader)
        {
            byte   index      = reader.ReadByte();
            int    version    = 0;
            string guid       = "";
            bool   hasMarker  = false;
            uint   entryCount = 0;

            try
            {
                if (index != 1)
                {
                    // I don't think those can actually occur more than once per file
                    while (index == 0xFC || index == 0xFD)
                    {
                        var bytes = new List <byte>(4);
                        bytes.Add(index);
                        bytes.AddRange(reader.ReadBytes(3));
                        UInt32 marker = BitConverter.ToUInt32(bytes.ToArray(), 0);
                        if (marker == GUID_MARKER)
                        {
                            guid  = IOFunctions.ReadCAString(reader, Encoding.Unicode);
                            index = reader.ReadByte();
                        }
                        else if (marker == VERSION_MARKER)
                        {
                            hasMarker = true;
                            version   = reader.ReadInt32();
                            index     = reader.ReadByte();
                            // break;
                        }
                        else
                        {
                            throw new DBFileNotSupportedException(string.Format("could not interpret {0}", marker));
                        }
                    }
                }
                entryCount = reader.ReadUInt32();
            }
            catch
            {
            }
            DBFileHeader header = new DBFileHeader(guid, version, entryCount, hasMarker);

            return(header);
        }
Exemplo n.º 7
0
 public override void Encode(BinaryWriter writer)
 {
     IOFunctions.WriteCAString(writer, Value.Trim(), stringEncoding);
 }
Exemplo n.º 8
0
 public override void Decode(BinaryReader reader)
 {
     Value = IOFunctions.ReadCAString(reader, stringEncoding);
 }