Exemple #1
0
        internal static GrfItem CreateV1(GrfArchive grf, string name, int compressedLength, int compressedLengthAligned, int realLength, GrfFileFlags flags, int position)
        {
            GrfItem ret = Create(grf, name, compressedLength, compressedLengthAligned, realLength, flags, position);

            ret.m_Flags |= (CheckExtension(name) ? GrfFileFlags.Des_0x14 : GrfFileFlags.MixCrypt);
            return(ret);
        }
Exemple #2
0
        private void ReadVer2Info()
        {
            if (m_IntVersion != 0x200)
            {
                throw new GrfException();
            }

            byte[] buf = new byte[8], zbuf;
            int    len, len2;

            FileStream.Read(buf, 0, 8);
            len = EndianConverter.LittleEndian(BitConverter.ToInt32(buf, 0));

            if (0 == (len2 = EndianConverter.LittleEndian(BitConverter.ToInt32(buf, 4))))
            {
                return;
            }

            zbuf = new byte[len];
            FileStream.Read(zbuf, 0, len);

            using (IntPtrEx pBuffer = new IntPtrEx(ZlibStream.UncompressBuffer(zbuf)))
            {
                string  name = null;
                GrfItem item;

                try
                {
                    for (int i = 0, offset = 0; i < m_Items.Capacity; i++, offset += 0x11)
                    {
                        name = pBuffer.Read <string>(offset);
                        len  = name.Length + 1;

                        if (len >= GRF_NAMELEN)
                        {
                            throw new GrfException();
                        }

                        offset += len;

                        item = GrfItem.CreateV2
                               (
                            this,
                            name,
                            EndianConverter.LittleEndian(pBuffer.Read <int>(offset)),
                            EndianConverter.LittleEndian(pBuffer.Read <int>(offset + 4)),
                            EndianConverter.LittleEndian(pBuffer.Read <int>(offset + 8)),
                            (GrfFileFlags)pBuffer[offset + 0xC],
                            EndianConverter.LittleEndian(pBuffer.Read <int>(offset + 0xD)) + GRF_HEADER_FULL_LEN
                               );

                        m_Items.GrfAdd(item);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
            }
        }
Exemple #3
0
 internal bool CheckExtension()
 {
     return(GrfItem.CheckExtension(m_Name));
 }
Exemple #4
0
        private void ReadVer1Info()
        {
            if (m_IntVersion > 0x103)
            {
                throw new GrfException();
            }

            int offset = (int)FileStream.Position;
            int len2, len = (int)FileStream.Length - offset;

            byte[] buffer = new byte[len], namebuf = new byte[GRF_NAMELEN];

            try
            {
                FileStream.Read(buffer, 0, len);

                string  name = null;
                GrfItem item;

                using (IntPtrEx pBuffer = new IntPtrEx(buffer))
                {
                    for (int i = offset = 0; i < m_Items.Capacity; i++)
                    {
                        len     = EndianConverter.LittleEndian(pBuffer.Read <int>(offset));
                        offset += 4;

                        if (m_IntVersion < 0x101)
                        {
                            len2 = pBuffer.Read <string>(offset).Length;
                            if (len2 >= GRF_NAMELEN)
                            {
                                throw new GrfException();
                            }

                            name = SwapNibbles(pBuffer + offset, len2);
                        }
                        else if (m_IntVersion < 0x104)
                        {
                            offset += 2;
                            len2    = len - 6;
                            if (len2 >= GRF_NAMELEN)
                            {
                                throw new GrfException();
                            }

                            SwapNibbles(namebuf, pBuffer + offset, len2);
                            name = GrfCrypt.DecryptNameVer1(namebuf, len2);

                            len -= 2;
                        }

                        offset += len;

                        item = GrfItem.CreateV1
                               (
                            this,
                            name,
                            EndianConverter.LittleEndian(pBuffer.Read <int>(offset)) - EndianConverter.LittleEndian(pBuffer.Read <int>(offset + 8)) - 0x02CB,
                            EndianConverter.LittleEndian(pBuffer.Read <int>(offset + 4)) - 0x92CB,
                            EndianConverter.LittleEndian(pBuffer.Read <int>(offset + 8)),
                            (GrfFileFlags)pBuffer[offset + 0xC],
                            EndianConverter.LittleEndian(pBuffer.Read <int>(offset + 0xD)) + GRF_HEADER_FULL_LEN
                               );

                        m_Items.GrfAdd(item);

                        offset += 0x11;
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }